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程序设计有所帮助。

相关文章

如何在Django配置文件里配置session链接

Django默认支持Session,并且默认是将Session数据存储在数据库中的 修改session存取放在数据库中 SESSION_ENGINE = 'django.cont...

python3安装crypto出错及解决方法

首先我用的python3.5的版本 问题的由来,我想通过python去实现RSA加密算法时,破解某网站的js加密认证,网上说需要安装pycrypto,我就去进行pip安装了 pip...

python字典setdefault方法和get方法使用实例

这篇文章主要介绍了python字典setdefault方法和get方法使用实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 在pyt...

python简单判断序列是否为空的方法

本文实例讲述了python简单判断序列是否为空的方法。分享给大家供大家参考。具体如下: 假设有如下序列: m1 = [] m2 = () m3 = {} 判断他们是否为空的高效...

python 类详解及简单实例

python 类详解 类 1.类是一种数据结构,可用于创建实例。(一般情况下,类封装了数据和可用于该数据的方法) 2.Python类是可调用的对象,即类对象 3.类通常在模块的顶层进...