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使用PyQt5的简单方法

python使用PyQt5的简单方法

一:安装PyQt5 pip install pyqt5 二:PyQt5简单使用 1:使用PyQt5创建一个简单窗口 import sys from PyQt5 import...

对python3 Serial 串口助手的接收读取数据方法详解

其实网上已经有许多python语言书写的串口,但大部分都是python2写的,没有找到一个合适的python编写的串口助手,只能自己来写一个串口助手,由于我只需要串口能够接收读取数据就可...

Python文本统计功能之西游记用字统计操作示例

Python文本统计功能之西游记用字统计操作示例

本文实例讲述了Python文本统计功能之西游记用字统计操作。分享给大家供大家参考,具体如下: 一、数据 xyj.txt,《西游记》的文本,2.2MB 致敬吴承恩大师,4020行(段) 二...

对Python中DataFrame按照行遍历的方法

在做分类模型时候,需要在DataFrame中按照行获取数据以便于进行训练和测试。 import pandas as pd dict=[[1,2,3,4,5,6],[2,3,4,5,6...

python+pygame实现坦克大战

python+pygame实现坦克大战

本文实例为大家分享了python+pygame实现坦克大战的具体代码,供大家参考,具体内容如下 一、首先导入pygame库 二、源码分享 #coding=utf-8 impo...