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中aioysql(异步操作MySQL)的方法

python异步IO初探 探索异步IO执之前,先说说IO的种类 1.阻塞IO最简单,即读写数据时,需要等待操作完成,才能继续执行。进阶的做法就是用多线程来处理需要IO的部分,缺点是开销会...

Django分页功能的实现代码详解

Django分页功能的实现代码详解

Django分页功能的实现 打开命令行窗口,创建Django工程,使用以下命令: django-admin startproject djpage cd djpage python ma...

Python中的os.path路径模块中的操作方法总结

解析路径 路径解析依赖与os中定义的一些变量: os.sep-路径各部分之间的分隔符。 os.extsep-文件名与文件扩展名之间的分隔符。 os.pardir-路径中表示...

利用Hyperic调用Python实现进程守护

利用Hyperic调用Python,实现进程守护,供大家参考,具体内容如下 调用操作系统方法获取进程信息,判断进程是否存在,Linux和Windows均支持,区别在于获取进程信息和启动...

Django框架 查询Extra功能实现解析

extra extra(select=None, where=None, params=None, tables=None, order_by=None, select_pa...