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字典多键值及重复键值的使用方法(详解)

python字典多键值及重复键值的使用方法(详解)

在Python中使用字典,格式如下: dict={ key1:value1 , key2;value2 ...} 在实际访问字典值时的使用格式如下: dict[key] 多...

pytorch中的自定义数据处理详解

pytorch在数据中采用Dataset的数据保存方式,需要继承data.Dataset类,如果需要自己处理数据的话,需要实现两个基本方法。 :.getitem:返回一条数据或者一个样本...

详解Python中的strftime()方法的使用

 strftime()方法转换成一个元组或struct_time表示时间所指定的格式参数所返回gmtime()或localtime()为一个字符串。 当t不设置,所返回当前时间...

Python使用sklearn实现的各种回归算法示例

Python使用sklearn实现的各种回归算法示例

本文实例讲述了Python使用sklearn实现的各种回归算法。分享给大家供大家参考,具体如下: 使用sklearn做各种回归 基本回归:线性、决策树、SVM、KNN 集成方法:随机森林...

python2.7 mayavi 安装图文教程(推荐)

python2.7 mayavi 安装图文教程(推荐)

工具:python2.7 相关包:traits-4.6.0-cp27-cp27m-win32.whl, VTK-7.1.1-cp27-cp27m-win32.whl, mayavi-4....