python显示生日是星期几的方法

yipeiwu_com5年前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使用Matplotlib实现Logos设计代码

Python使用Matplotlib实现Logos设计代码

本文主要展示了使用matplotlib设计logo的示例及完整代码,首先看下其演示结果: Python代码如下: import numpy as np import matplot...

简单解析Django框架中的表单验证

我们的搜索示例仍然相当地简单,特别从数据验证方面来讲;我们仅仅只验证搜索关键值是否为空。 然后许多HTML表单包含着比检测值是否为空更为复杂的验证。 我们都有在网站上见过类似以下的错误提...

pip 错误unused-command-line-argument-hard-error-in-future解决办法

在我的Mac Air上,用pip安装一些Python库时,偶尔就会遇到一些报错,关于“unused-command-line-argument-hard-error-in-future”...

python保留小数位的三种实现方法

前言 保留小数位是我们经常会碰到的问题,尤其是刷题过程中。那么在python中保留小数位的方法也非常多,但是笔者的原则就是什么简单用什么,因此这里介绍几种比较简单实用的保留小数位的方法:...

Python对象转换为json的方法步骤

Python中内置了json库,用起来超级方便,json现在以成为开发的必备。 python对象到json字符串的转换规则: Python...