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中的深浅拷贝,需要搞清楚下面一系列概念: 变量-引用-对象(可变对象,不可变对象)-切片-拷贝(浅拷贝,深拷贝) 【变量-对象-引用】 在Python中一切都是对象,...

Numpy 将二维图像矩阵转换为一维向量的方法

以下的例子,将32x32的二维矩阵,装换成1x1024的向量 def image2vector (filename): returnVect=zeros((1,1024)) f=...

python使用xpath中遇到:<Element a at 0x39a9a80>到底是什么?

前言 大家在学习python爬虫的过程中,会发现一个问题,语法我看完了,说的也很详细,我也认真看了,爬虫还是不会写,或者没有思路,所以我的所有文章都会从实例的角度来解析一些常见的问题和...

Python文件去除注释的方法

本文实例讲述了Python文件去除注释的方法。分享给大家供大家参考。具体实现方法如下: #!/usr/bin/python # -*- coding: GBK -*- #writ...

python使用opencv读取图片的实例

安装好环境后,开始了第一个Hello word 例子,如何读取图片,保存图品 import cv2 import numpy as np import matplotlib.py...