Python 生成日曆

Document 對象參考手冊 Python3 實例

以下代碼用於生成指定日期的日曆:

實例(Python 3.0+)

# Filename : test.py # author by : www.xuhuhu.com # 引入日曆模組 import calendar # 輸入指定年月 yy = int(input("輸入年份: ")) mm = int(input("輸入月份: ")) # 顯示日曆 print(calendar.month(yy,mm))

執行以上代碼輸出結果為:

輸入年份: 2015
輸入月份: 6
     June 2015
Mo Tu We Th Fr Sa Su
 1  2  3  4  5  6  7
 8  9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30

Document 對象參考手冊 Python3 實例