日历模块允许输出类似于程序的日历,并提供与日历相关的其他有用函数。 “日历”模块中定义的函数和类使用理想化的日历,当前的公历日历在两个方向上都无限期扩展。
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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。