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

相关文章

pyqt5 实现工具栏文字图片同时显示

如下所示: import sys from PyQt5.QtWidgets import QMainWindow, QTextEdit, QAction, QApplication...

Python使用logging结合decorator模式实现优化日志输出的方法

本文实例讲述了Python使用logging结合decorator模式实现优化日志输出的方法。分享给大家供大家参考,具体如下: python内置的loging模块非常简便易用, 很适合程...

python实现分页效果

python实现分页效果

本文实例为大家分享了python实现分页效果展示的具体代码,供大家参考,具体内容如下 难点:清空Layout #!/usr/bin/python #-*-coding:utf-...

Flask 上传自定义头像的实例详解

Flask 上传自定义头像的实例详解

Flask Web 开发这本书基本上做完了,后面还需要温习,但是自己做的博客总觉得简陋了点,所以,在动脑子开发新功能 今天想到最基本的功能,自定义头像 那这样的功能,设计到2大基本功能块...

python日期时间转为字符串或者格式化输出的实例

如下所示: 年月日时分秒 >>> print datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") 2017-...