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

yipeiwu_com5年前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中使用Counter进行字典创建以及key数量统计的方法

这里的Counter是指collections中的Counter,通过Counter可以实现字典的创建以及字典key出现频次的统计。然而,使用的时候还是有一点需要注意的小事项。 使用Co...

使用Numpy读取CSV文件,并进行行列删除的操作方法

Numpy是Python强大的数据计算和处理模块,其操作数据非常迅速且简单易行。 首先读取CSV文件 >>> import numpy as np#导入numpy模...

python中for用来遍历range函数的方法

python中for用来遍历range函数的方法

栗子:计算斐波那契数列(任一个数都是前两个数之和的数字序列) Python2.7实现代码如下: <strong><span style="font-size:14p...

python3中替换python2中cmp函数的实现

python3中替换python2中cmp函数的实现

python 3.4.3 的版本中已经没有cmp函数,被operator模块代替,在交互模式下使用时,需要导入模块。 在没有导入模块情况下,会出现 提示找不到cmp函数了,那么在p...

Python文件操作中进行字符串替换的方法(保存到新文件/当前文件)

题目: 1.首先将文件:/etc/selinux/config 进行备份 文件名为 /etc/selinux/config.bak 2.再文件:/etc/selinux/config 中...