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实现用户管理系统的具体代码,供大家参考,具体内容如下 《python核心编程》第七章练习题第五题 一、题目描述  userpw2.py。下面的...

对Python字符串中的换行符和制表符介绍

有关换行的问题 首先提一个问题,如下。 python程序代码如下: print("I'm Bob. What's your name?") 上一行代码的输出如下: I...

初步剖析C语言编程中的结构体

C语言结构体,可谓是C强大功能之一,也是C++语言之所以能衍生的有利条件,事实上,当结构体中成员中有函数指针了后,那么,结构体也即C++中的类了。 C语言中,结构体的声明、定义是用到关键...

python中threading超线程用法实例分析

本文实例讲述了python中threading超线程用法。分享给大家供大家参考。具体分析如下: threading基于Java的线程模型设计。锁(Lock)和条件变量(Condition...

pygame加载中文名mp3文件出现error

pygame加载中文名mp3文件出现error

前言:  今天刚刚做了个音乐列表,但笔者发现在指定目录mp3文件名为中文时,便出现pygame.error,不能正确加载指定mp3文件.写好的代码不想再改了,来个小测试吧 pygame播...