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 统计一个列表当中的每一个元素出现了多少次的方法

如下所示: #coding=utf-8 #方式一 print('*'*20 + '方式一' + '*'*20) li1 = [1,2,2,3,3,3,4,4,4,4,5,5,5,5,...

python调用c++传递数组的实例

如下所示: INPUT = c_int * 4 # 实例化一个长度为2的整型数组 input = INPUT() # 为数组赋值(input这个数组是不支持迭代的) input[0]...

图解Python变量与赋值

图解Python变量与赋值

Python是一门独特的语言,与C语言有很大区别,初学Python很多萌新表示对变量与赋值不理解,学过C的都知道,给变量赋值时,需要先指定数据类型,同时会开辟一块内存区域,用于存储值,例...

利用pyuic5将ui文件转换为py文件的方法

利用pyuic5将ui文件转换为py文件的方法

操作系统上正确配置python环境之后,pyuic5也是一个可以识别的命令行指令 到.ui文件的目录下,直接cmd进入,输入pyuic5 -o 转换的py文件 待转换的ui文件 此时,...

python 时间信息“2018-02-04 18:23:35“ 解析成字典形式的结果代码详解

python 时间信息“2018-02-04 18:23:35“ 解析成字典形式的结果代码详解

将时间信息“2018-02-04  18:23:35“ 解析成字典形式的结果 如:{‘year':2018,‘month':2,‘day':4,‘hour':18:‘minut...