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图形用户界面和游戏开发知识点

基于tkinter模块的GUI GUI是图形用户界面的缩写,图形化的用户界面对使用过计算机的人来说应该都不陌生,在此也无需进行赘述。Python默认的GUI开发模块是tkinter(在...

Python的Bottle框架中获取制定cookie的教程

这两天为用bottle+mongodb写的一个项目加上登录功能,无奈怎么都获取不到保存的cookie,文档给出让我们这样操作cookie的代码片段: @route('/login')...

python实现两个dict合并与计算操作示例

本文实例讲述了python实现两个dict合并与计算操作。分享给大家供大家参考,具体如下: 用pythonic 的方法,将两个dict合并,并进行计算. 如果key值相同,则将他们的值进...

Python求正态分布曲线下面积实例

Python求正态分布曲线下面积实例

正态分布应用最广泛的连续概率分布,其特征是“钟”形曲线。这种分布的概率密度函数为: 其中,μ为均值,σ为标准差。 求正态分布曲线下面积有3σ原则: 正态曲线下,横轴区间(μ-σ,μ+...

python中的print()输出

1.普通的输出: print(str)#str是任意一个字符串,数字··· 2.格式化输出: print('1,2,%s,%d'%('asd',4)) 1,2,asd,4 与C语...