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实现的个人所得税计算器。分享给大家供大家参考,具体如下: # -*- coding: utf-8 -*- """ Created on Sat Apr 15...

Python最小二乘法矩阵

最小二乘法矩阵 #! /usr/bin/env python # -*- coding: utf-8 -*- import numpy as np def calc_left_k_m...

Windows上配置Emacs来开发Python及用Python扩展Emacs

Windows下配置Emacs来开发Python 去年在网上偶然的一个机会知道了Emacs的存在,在周围前辈们都在夸赞Sublime好用的时候,喜欢跟大众唱反调的我,突然觉得如果能用Em...

跟老齐学Python之类的细节

这几天和几个朋友以各种途径讨论过OOP的相关问题,他们是:令狐虫、Frank、晋剑、小冯 大家对OOP有不同看法,所谓工程派和学院派看法不一致。从应用的角度看,工程派的观点是值得推荐的,...

Python中.py文件打包成exe可执行文件详解

Python中.py文件打包成exe可执行文件详解

前言 最近做了几个简单的爬虫python程序,于是就想做个窗口看看效果。 首先是,窗口的话,以前没怎么接触过,就先考虑用Qt制作简单的ui。这里用前面sinanews的爬虫脚本为例,制作...