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

相关文章

简单介绍Ruby中的CGI编程

Ruby 是一门通用的语言,不仅仅是一门应用于WEB开发的语言,但 Ruby 在WEB应用及WEB工具中的开发是最常见的。 使用Ruby您不仅可以编写自己的SMTP服务器,FTP程序,或...

python 定时器每天就执行一次的实现代码

1.实现功能 编写python脚本一直运行,判断当下是否是新的一天,如果是就执行一次任务代码 2.具体实现代码 #-*-coding:utf-8 -*- __author__ = '...

python检测文件夹变化,并拷贝有更新的文件到对应目录的方法

检测文件夹,拷贝有更新的文件到对应目录 2016.5.19 亲测可用,若有借鉴请修改下文件路径; 学习python小一个月后写的这个功能,属于初学,若有大神路过,求代码优化~ newco...

python实现微信机器人: 登录微信、消息接收、自动回复功能

python实现微信机器人: 登录微信、消息接收、自动回复功能

安装wxpy pip install -U wxpy 登录微信 # 导入模块 from wxpy import * # 初始化机器人,扫码登陆 bot = Bot() 运行以...

详解Python中的from..import绝对导入语句

相对或者绝对import 更多的复杂部分已经从python2.5以来实现:导入一个模块可以指定使用绝对或者包相对的导入。这个计划将移动到使绝对的导入成为默认的细节在其他版本的pytho...