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中回文数和质数的问题

解决Python中回文数和质数的问题

一、前言 今天学习视频时课后作业是找出1000以内既是素数又是回文数的数,写代码这个很容易,结果一运行遇到了bug,输出结果跟预期不一样,调试了快30min,再接着一通搜索和回看视频才发...

Python os模块介绍

os.getcwd() 获取当前工作目录,即当前python脚本工作的目录路径 os.chdir("dirname") 改变当前脚本工作目录;相当于shell下cd os.cur...

python删除列表内容

今天有点囧 a=['XXXX_game.sql', 'XXXX_game_sp.sql', 'XXXX_gamelog_sp.sql', 'XXXX_gamelog.sql'] fo...

pyqt5 使用label控件实时显示时间的实例

pyqt5 使用label控件实时显示时间的实例

如下所示: import sys from PyQt5 import QtGui, QtCore, QtWidgets from PyQt5.QtWidgets import * f...

使用python PIL库实现简单验证码的去噪方法步骤

使用python PIL库实现简单验证码的去噪方法步骤

字符型图片验证码识别完整过程及Python实现的博主,我的大部分知识点都是从他那里学来的。 想要识别验证码,收集足够多的样本后,首先要做的就是对验证码原始图片进行处理,对验证码识别分类之...