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

相关文章

Django 重写用户模型的实现

Django内建的User模型可能不适合某些类型的项目。例如,在某些网站上使用邮件地址而不是用户名作为身份的标识可能更合理。 1.修改配置文件,覆盖默认的User模型 Django允...

Python高斯消除矩阵

高斯消除矩阵 #! /usr/bin/env python # -*- coding: utf-8 -*- # def pprint(A): for i in A: pr...

pandas中遍历dataframe的每一个元素的实现

假如有一个需求场景需要遍历一个csv或excel中的每一个元素,判断这个元素是否含有某个关键字 那么可以用python的pandas库来实现。 方法一: pandas的dataframe...

python正则表达式re模块详解

快速入门 import re pattern = 'this' text = 'Does this text match the pattern?' match = re...

python3操作微信itchat实现发送图片

python3操作微信itchat实现发送图片

两个代码,一个是把python当微信操作,可以查看自己的好友信息,群信息等。还可以定时发送文本,文件等。效果就和你本人操作一样,没差别。 还有一个是连接你的微信和图灵机器人,别人和你说话...