python显示生日是星期几的方法

yipeiwu_com6年前Python基础

本文实例讲述了python显示生日是星期几的方法。分享给大家供大家参考。具体实现方法如下:

# find the day of the week of a given date
# Python will trap impossible dates like (1900, 2, 29)
# tested with Python24   vegaseat  01aug2005
from datetime import date
# a typical birthday year, month, day 
# or change it to your own birthday... 
birthday = date(1983, 12, 25)
dayList = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
# date.weekday() returns 0 for Monday and so on, so pick the day string from the dayList
print "The day of the week on %s was a %s" % (birthday.strftime("%d%b%Y"), dayList[date.weekday(birthday)])

希望本文所述对大家的Python程序设计有所帮助。

相关文章

Python Pandas 获取列匹配特定值的行的索引问题

Python Pandas 获取列匹配特定值的行的索引问题

给定一个带有列"BoolCol"的DataFrame,如何找到满足条件"BoolCol" == True的DataFrame的索引 目前有迭代的方式来做到这一点: for i in...

Python三级菜单的实例

要求: 打印省、市、县三级菜单 可返回上一级 可随时退出程序 版本1 # _author : Ahern Li # @_date : 2017/9/12 menu = { '浙...

python中安装模块包版本冲突问题的解决

问题 最近在工作中遇到一个问题,在安装python软件包的时候,经常会遇类似这样一个问题。比如对于ipython,机子本身安装的版本是1.2.1,显然太低,不足以跑jupyter,尝试...

Python读写txt文本文件的操作方法全解析

Python读写txt文本文件的操作方法全解析

一、文件的打开和创建 >>> f = open('/tmp/test.txt') >>> f.read() 'hello python!\nhel...

解决Python中pandas读取*.csv文件出现编码问题

解决Python中pandas读取*.csv文件出现编码问题

1、问题 在使用Python中pandas读取csv文件时,由于文件编码格式出现以下问题: Traceback (most recent call last): File "pan...