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基于Tkinter模块实现的弹球小游戏

Python基于Tkinter模块实现的弹球小游戏

本文实例讲述了Python基于Tkinter模块实现的弹球小游戏。分享给大家供大家参考,具体如下: #!usr/bin/python #-*- coding:utf-8 -*- fr...

python网络编程之文件下载实例分析

本文实例讲述了python网络编程之文件下载实现方法。分享给大家供大家参考。具体如下: 真是越看越喜欢python啊,想要了解它提供的http和ftp下载功能,原来是如此的简单。 1、相...

利用pyinstaller将py文件打包为exe的方法

利用pyinstaller将py文件打包为exe的方法

写在前面 做大创的时候,因为需要计算合金的各种能量、温度等一大堆数据,为了能够福泽后来的学弟学妹,我决定将我处理数据时用的python程序打包成exe,这样就可以在没有安装python环...

PyCharm使用之配置SSH Interpreter的方法步骤

PyCharm使用之配置SSH Interpreter的方法步骤

在文章PyCharm使用之利用Docker镜像搭建Python开发环境中,该文章介绍了在PyCharm中如何利用Docker镜像搭建Python开发环境。在本文中,将会介绍如何使用PyC...

python 判断文件还是文件夹的简单实例

如下所示: import os if os.path.isdir(path): print "it's a directory" elif os.path.isfile(path...