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生成器与迭代器详解

列表生成式: 例一: a = [i+1 for i in range(10)] print(a) 输出: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] 例二...

解决pandas中读取中文名称的csv文件报错的问题

之前在使用Pandas处理csv文件时,发现如果文件名为中文,则会报错: OSError: Initializing from file failed 后来在一位博主的博客中解释了...

Python Web框架Flask信号机制(signals)介绍

信号(signals) Flask信号(signals, or event hooking)允许特定的发送端通知订阅者发生了什么(既然知道发生了什么,那我们可以知道接下来该做什么了)。...

Python安装tar.gz格式文件方法详解

Python安装tar.gz格式文件方法详解

这篇文章主要介绍了Python安装tar.gz格式文件方法详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 有的库没有找到对应的.w...

Python中常用的内置方法

Python中常用的内置方法

1.最大值 max(3,4) ##运行结果为4 2.最小值 min(3,4) ##运行结果为3 3.求和 sum(range(1,101)) ##求1~100的和...