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 contrib Comments 评论模块(详解)

老版本的Django中自带一个评论框架。但是从1.6版本后,该框架独立出去了,也就是本文的评论插件。 这个插件可给models附加评论,因此常被用于为博客文章、图片、书籍章节或其它任何东...

Python 装饰器深入理解

讲 Python 装饰器前,我想先举个例子,虽有点污,但跟装饰器这个话题很贴切。 每个人都有的内裤主要功能是用来遮羞,但是到了冬天它没法为我们防风御寒,咋办?我们想到的一个办法就是把内裤...

解决Pycharm后台indexing导致不能run的问题

解决Pycharm后台indexing导致不能run的问题

file >>setting>> Project  >>Project Structure   点击add c...

ORM Django 终端打印 SQL 语句实现解析

ORM Django 终端打印 SQL 语句实现解析

在 settings.py 中添加以下内容: LOGGING = { 'version': 1, 'disable_existing_loggers': False, '...

Python中int()函数的用法浅析

int()是Python的一个内部函数  Python系统帮助里面是这么说的 >>> help(int) Help on class int in...