日曆模塊允許輸出類似於程序的日曆,並提供與日曆相關的其他有用函數。 “日曆”模塊中定義的函數和類使用理想化的日曆,當前的公曆日曆在兩個方向上都無限期擴展。
Python中的yeardayscalendar()方法用於獲取指定年份的數據。周列表中的條目是天數。這個月以外的天數為零。
用法: yeardayscalendar(year, width) 參數: year: year of the calendar width: [Default:3] number of months in each row. 返回: list of day numbers.
代碼1:
# Python program to demonstrate working
# of yeardayscalendar() method
# importing calendar module
import calendar
obj = calendar.Calendar()
year = 2016
# default value of width is 3
# priting with yeardayscalendar
print(obj.yeardayscalendar(year))
輸出:
[[[[0, 0, 0, 0, 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, 31]], [[1, 2, 3, 4, 5, 6, 7]…
…
[[0, 0, 0, 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, 31, 0]]]]
代碼2:列出星期
# Python program to demonstrate working
# of yeardayscalendar() method
# importing calendar module
import calendar
obj = calendar.Calendar()
# iteratign with yeardayscalendar
for day in obj.yeardayscalendar(2018, 1):
print(day)
輸出:
[[[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, 31, 0, 0, 0, 0]]]
[[[0, 0, 0, 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, 0, 0, 0, 0]]]
…
[[[0, 0, 0, 0, 0, 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], [31, 0, 0, 0, 0, 0, 0]]]
相關用法
- Python calendar itermonthdays()用法及代碼示例
- Python calendar setfirstweekday()用法及代碼示例
- Python calendar firstweekday()用法及代碼示例
- Python calendar isleap()用法及代碼示例
- Python calendar iterweekdays()用法及代碼示例
- Python calendar itermonthdays2()用法及代碼示例
- Python calendar monthdatescalendar()用法及代碼示例
- Python calendar leapdays()用法及代碼示例
- Python calendar yeardays2calendar()用法及代碼示例
- Python calendar yeardatescalendar()用法及代碼示例
- Python calendar monthdayscalendar()用法及代碼示例
- Python calendar monthdays2calendar()用法及代碼示例
- Python calendar prmonth()用法及代碼示例
- Python calendar formatyear()用法及代碼示例
- Python calendar itermonthdates()用法及代碼示例
注:本文由純淨天空篩選整理自Shivam_k大神的英文原創作品 Python calendar module | yeardayscalendar() method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。