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编写简单的端口扫描器的实例分享

单线程实现 单线程实现道理比较简单,这里尝试Soket连接3389,连接成功说明端口开放,否则说明没有开远程服务。随便修改了一下就ok了,代码如下,最终得到自己的IP地址。 #!/u...

python re正则表达式模块(Regular Expression)

模块的的作用主要是用于字符串和文本处理,查找,搜索,替换等 复习一下基本的正则表达式吧  .:匹配除了换行符以为的任意单个字符  *:匹配任意字符,一个,零个,多个都...

Ubuntu 16.04 LTS中源码安装Python 3.6.0的方法教程

前提 官网上提供了 Mac 和 Windows 上的安装包和 Linux 上安装需要的源码。 下载地址如下: https://www.python.org/downloads/relea...

Python谱减法语音降噪实例

代码中用到了nextpow2,其中n = nextpow2(x) 表示最接近x的2的n次幂。 #!/usr/bin/env python import numpy as np imp...

python使用numpy实现直方图反向投影示例

python使用numpy实现直方图反向投影示例

最近跟着OpenCV2-Python-Tutorials在学习python_opencv中直方图的反向投影时,第一种方法是使用numpy实现将图中的红色玫瑰分割出来,教程给的代码缺了一句...