python 示例
Python Calendar.yeardatescalendar()方法 (Python Calendar.yeardatescalendar() Method)
Calendar.yeardatescalendar() method is an inbuilt method of the Calendar class of calendar module in Python. It uses an instance of this class and returns a list of month rows for the given year.
Calendar.yeardatescalendar()方法是Python中Calendar模块的Calendar类的内置方法。 它使用此类的实例,并返回给定年份的月份行列表。
Here, each month contains full weeks, ie, all the weeks in a month will have 7 values, even if the value of a day in the week is outside of the given month. Each week list consists of seven datetime.date objects.
在这里,每个月包含整周,即,即使一周中某天的值在给定月份之外,一个月中的所有周也将具有7个值。 每个星期列表由七个datetime.date对象组成。
Module:
模块:
import calendar
Class:
类:
from calendar import Calendar
Syntax:
句法:
yeardatescalendar(year, width =3)
Parameter(s):
参数:
year: It is a required parameter, which specifies the year of the calendar.
year :这是必填参数,用于指定日历的年份。
width: It is an optional parameter, which specifies the width of the month value; default value = 3.
width :这是一个可选参数,用于指定月份值的宽度; 默认值= 3。
Return value:
返回值:
The return type of this method is <class 'list'>, it returns a list of month rows giving datetime.date objects.
此方法的返回类型为<class'list'> ,它返回给出datetime.date对象的月份行的列表。
Example:
例:
# Python program to illustrate the
# use of monthdayscalendar() method
# import class
import calendar
# Creating Calendar Instance
cal = calendar.Calendar()
# default firstweekday =0
year = 2011
month = 11
print(cal.monthdayscalendar(year, month))
print()
# always full weeks are listed.
# set the firstweekday to 3
cal = calendar.Calendar(firstweekday = 3)
year = 1998
month = 8
print(cal.monthdayscalendar(year, month))
print()
Output
输出量
[[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, 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]]
Example:
例:
# Python program to illustrate the
# use of yeardatescalendar() method
# import class
import calendar
# Creating Calendar Instance
cal = calendar.Calendar()
year = 2019
# Changing the width to 5
print(cal.yeardatescalendar(year, width = 5))
print()
Output
输出量
[[[[
datetime.date(2018, 12, 31),
datetime.date(2019, 1, 1),
datetime.date(2019, 1, 2),
datetime.date(2019, 1, 3),
datetime.date(2019, 1, 4),
datetime.date(2019, 1, 5),
datetime.date(2019, 1, 6),
], [
datetime.date(2019, 1, 7),
datetime.date(2019, 1, 8),
datetime.date(2019, 1, 9),
datetime.date(2019, 1, 10),
datetime.date(2019, 1, 11),
datetime.date(2019, 1, 12),
datetime.date(2019, 1, 13),
], [
datetime.date(2019, 1, 14),
datetime.date(2019, 1, 15),
datetime.date(2019, 1, 16),
datetime.date(2019, 1, 17),
datetime.date(2019, 1, 18),
datetime.date(2019, 1, 19),
datetime.date(2019, 1, 20),
], [
datetime.date(2019, 1, 21),
datetime.date(2019, 1, 22),
datetime.date(2019, 1, 23),
datetime.date(2019, 1, 24),
datetime.date(2019, 1, 25),
datetime.date(2019, 1, 26),
datetime.date(2019, 1, 27),
], [
datetime.date(2019, 1, 28),
datetime.date(2019, 1, 29),
datetime.date(2019, 1, 30),
datetime.date(2019, 1, 31),
datetime.date(2019, 2, 1),
datetime.date(2019, 2, 2),
datetime.date(2019, 2, 3),
]], [[
datetime.date(2019, 1, 28),
datetime.date(2019, 1, 29),
datetime.date(2019, 1, 30),
datetime.date(2019, 1, 31),
datetime.date(2019, 2, 1),
datetime.date(2019, 2, 2),
datetime.date(2019, 2, 3),
], [
datetime.date(2019, 2, 4),
datetime.date(2019, 2, 5),
datetime.date(2019, 2, 6),
datetime.date(2019, 2, 7),
datetime.date(2019, 2, 8),
datetime.date(2019, 2, 9),
datetime.date(2019, 2, 10),
], [
datetime.date(2019, 2, 11),
datetime.date(2019, 2, 12),
datetime.date(2019, 2, 13),
datetime.date(2019, 2, 14),
datetime.date(2019, 2, 15),
datetime.date(2019, 2, 16),
datetime.date(2019, 2, 17),
], [
datetime.date(2019, 2, 18),
datetime.date(2019, 2, 19),
datetime.date(2019, 2, 20),
datetime.date(2019, 2, 21),
datetime.date(2019, 2, 22),
datetime.date(2019, 2, 23),
datetime.date(2019, 2, 24),
], [
datetime.date(2019, 2, 25),
datetime.date(2019, 2, 26),
datetime.date(2019, 2, 27),
datetime.date(2019, 2, 28),
datetime.date(2019, 3, 1),
datetime.date(2019, 3, 2),
datetime.date(2019, 3, 3),
]], [[
datetime.date(2019, 2, 25),
datetime.date(2019, 2, 26),
datetime.date(2019, 2, 27),
datetime.date(2019, 2, 28),
datetime.date(2019, 3, 1),
datetime.date(2019, 3, 2),
datetime.date(2019, 3, 3),
], [
datetime.date(2019, 3, 4),
datetime.date(2019, 3, 5),
datetime.date(2019, 3, 6),
datetime.date(2019, 3, 7),
datetime.date(2019, 3, 8),
datetime.date(2019, 3, 9),
datetime.date(2019, 3, 10),
], [
datetime.date(2019, 3, 11),
datetime.date(2019, 3, 12),
datetime.date(2019, 3, 13),
datetime.date(2019, 3, 14),
datetime.date(2019, 3, 15),
datetime.date(2019, 3, 16),
datetime.date(2019, 3, 17),
], [
datetime.date(2019, 3, 18),
datetime.date(2019, 3, 19),
datetime.date(2019, 3, 20),
datetime.date(2019, 3, 21),
datetime.date(2019, 3, 22),
datetime.date(2019, 3, 23),
datetime.date(2019, 3, 24),
], [
datetime.date(2019, 3, 25),
datetime.date(2019, 3, 26),
datetime.date(2019, 3, 27),
datetime.date(2019, 3, 28),
datetime.date(2019, 3, 29),
datetime.date(2019, 3, 30),
datetime.date(2019, 3, 31),
]], [[
datetime.date(2019, 4, 1),
datetime.date(2019, 4, 2),
datetime.date(2019, 4, 3),
datetime.date(2019, 4, 4),
datetime.date(2019, 4, 5),
datetime.date(2019, 4, 6),
datetime.date(2019, 4, 7),
], [
datetime.date(2019, 4, 8),
datetime.date(2019, 4, 9),
datetime.date(2019, 4, 10),
datetime.date(2019, 4, 11),
datetime.date(2019, 4, 12),
datetime.date(2019, 4, 13),
datetime.date(2019, 4, 14),
], [
datetime.date(2019, 4, 15),
datetime.date(2019, 4, 16),
datetime.date(2019, 4, 17),
datetime.date(2019, 4, 18),
datetime.date(2019, 4, 19),
datetime.date(2019, 4, 20),
datetime.date(2019, 4, 21),
], [
datetime.date(2019, 4, 22),
datetime.date(2019, 4, 23),
datetime.date(2019, 4, 24),
datetime.date(2019, 4, 25),
datetime.date(2019, 4, 26),
datetime.date(2019, 4, 27),
datetime.date(2019, 4, 28),
], [
datetime.date(2019, 4, 29),
datetime.date(2019, 4, 30),
datetime.date(2019, 5, 1),
datetime.date(2019, 5, 2),
datetime.date(2019, 5, 3),
datetime.date(2019, 5, 4),
datetime.date(2019, 5, 5),
]], [[
datetime.date(2019, 4, 29),
datetime.date(2019, 4, 30),
datetime.date(2019, 5, 1),
datetime.date(2019, 5, 2),
datetime.date(2019, 5, 3),
datetime.date(2019, 5, 4),
datetime.date(2019, 5, 5),
], [
datetime.date(2019, 5, 6),
datetime.date(2019, 5, 7),
datetime.date(2019, 5, 8),
datetime.date(2019, 5, 9),
datetime.date(2019, 5, 10),
datetime.date(2019, 5, 11),
datetime.date(2019, 5, 12),
], [
datetime.date(2019, 5, 13),
datetime.date(2019, 5, 14),
datetime.date(2019, 5, 15),
datetime.date(2019, 5, 16),
datetime.date(2019, 5, 17),
datetime.date(2019, 5, 18),
datetime.date(2019, 5, 19),
], [
datetime.date(2019, 5, 20),
datetime.date(2019, 5, 21),
datetime.date(2019, 5, 22),
datetime.date(2019, 5, 23),
datetime.date(2019, 5, 24),
datetime.date(2019, 5, 25),
datetime.date(2019, 5, 26),
], [
datetime.date(2019, 5, 27),
datetime.date(2019, 5, 28),
datetime.date(2019, 5, 29),
datetime.date(2019, 5, 30),
datetime.date(2019, 5, 31),
datetime.date(2019, 6, 1),
datetime.date(2019, 6, 2),
]]], [[[
datetime.date(2019, 5, 27),
datetime.date(2019, 5, 28),
datetime.date(2019, 5, 29),
datetime.date(2019, 5, 30),
datetime.date(2019, 5, 31),
datetime.date(2019, 6, 1),
datetime.date(2019, 6, 2),
], [
datetime.date(2019, 6, 3),
datetime.date(2019, 6, 4),
datetime.date(2019, 6, 5),
datetime.date(2019, 6, 6),
datetime.date(2019, 6, 7),
datetime.date(2019, 6, 8),
datetime.date(2019, 6, 9),
], [
datetime.date(2019, 6, 10),
datetime.date(2019, 6, 11),
datetime.date(2019, 6, 12),
datetime.date(2019, 6, 13),
datetime.date(2019, 6, 14),
datetime.date(2019, 6, 15),
datetime.date(2019, 6, 16),
], [
datetime.date(2019, 6, 17),
datetime.date(2019, 6, 18),
datetime.date(2019, 6, 19),
datetime.date(2019, 6, 20),
datetime.date(2019, 6, 21),
datetime.date(2019, 6, 22),
datetime.date(2019, 6, 23),
], [
datetime.date(2019, 6, 24),
datetime.date(2019, 6, 25),
datetime.date(2019, 6, 26),
datetime.date(2019, 6, 27),
datetime.date(2019, 6, 28),
datetime.date(2019, 6, 29),
datetime.date(2019, 6, 30),
]], [[
datetime.date(2019, 7, 1),
datetime.date(2019, 7, 2),
datetime.date(2019, 7, 3),
datetime.date(2019, 7, 4),
datetime.date(2019, 7, 5),
datetime.date(2019, 7, 6),
datetime.date(2019, 7, 7),
], [
datetime.date(2019, 7, 8),
datetime.date(2019, 7, 9),
datetime.date(2019, 7, 10),
datetime.date(2019, 7, 11),
datetime.date(2019, 7, 12),
datetime.date(2019, 7, 13),
datetime.date(2019, 7, 14),
], [
datetime.date(2019, 7, 15),
datetime.date(2019, 7, 16),
datetime.date(2019, 7, 17),
datetime.date(2019, 7, 18),
datetime.date(2019, 7, 19),
datetime.date(2019, 7, 20),
datetime.date(2019, 7, 21),
], [
datetime.date(2019, 7, 22),
datetime.date(2019, 7, 23),
datetime.date(2019, 7, 24),
datetime.date(2019, 7, 25),
datetime.date(2019, 7, 26),
datetime.date(2019, 7, 27),
datetime.date(2019, 7, 28),
], [
datetime.date(2019, 7, 29),
datetime.date(2019, 7, 30),
datetime.date(2019, 7, 31),
datetime.date(2019, 8, 1),
datetime.date(2019, 8, 2),
datetime.date(2019, 8, 3),
datetime.date(2019, 8, 4),
]], [[
datetime.date(2019, 7, 29),
datetime.date(2019, 7, 30),
datetime.date(2019, 7, 31),
datetime.date(2019, 8, 1),
datetime.date(2019, 8, 2),
datetime.date(2019, 8, 3),
datetime.date(2019, 8, 4),
], [
datetime.date(2019, 8, 5),
datetime.date(2019, 8, 6),
datetime.date(2019, 8, 7),
datetime.date(2019, 8, 8),
datetime.date(2019, 8, 9),
datetime.date(2019, 8, 10),
datetime.date(2019, 8, 11),
], [
datetime.date(2019, 8, 12),
datetime.date(2019, 8, 13),
datetime.date(2019, 8, 14),
datetime.date(2019, 8, 15),
datetime.date(2019, 8, 16),
datetime.date(2019, 8, 17),
datetime.date(2019, 8, 18),
], [
datetime.date(2019, 8, 19),
datetime.date(2019, 8, 20),
datetime.date(2019, 8, 21),
datetime.date(2019, 8, 22),
datetime.date(2019, 8, 23),
datetime.date(2019, 8, 24),
datetime.date(2019, 8, 25),
], [
datetime.date(2019, 8, 26),
datetime.date(2019, 8, 27),
datetime.date(2019, 8, 28),
datetime.date(2019, 8, 29),
datetime.date(2019, 8, 30),
datetime.date(2019, 8, 31),
datetime.date(2019, 9, 1),
]], [
[
datetime.date(2019, 8, 26),
datetime.date(2019, 8, 27),
datetime.date(2019, 8, 28),
datetime.date(2019, 8, 29),
datetime.date(2019, 8, 30),
datetime.date(2019, 8, 31),
datetime.date(2019, 9, 1),
],
[
datetime.date(2019, 9, 2),
datetime.date(2019, 9, 3),
datetime.date(2019, 9, 4),
datetime.date(2019, 9, 5),
datetime.date(2019, 9, 6),
datetime.date(2019, 9, 7),
datetime.date(2019, 9, 8),
],
[
datetime.date(2019, 9, 9),
datetime.date(2019, 9, 10),
datetime.date(2019, 9, 11),
datetime.date(2019, 9, 12),
datetime.date(2019, 9, 13),
datetime.date(2019, 9, 14),
datetime.date(2019, 9, 15),
],
[
datetime.date(2019, 9, 16),
datetime.date(2019, 9, 17),
datetime.date(2019, 9, 18),
datetime.date(2019, 9, 19),
datetime.date(2019, 9, 20),
datetime.date(2019, 9, 21),
datetime.date(2019, 9, 22),
],
[
datetime.date(2019, 9, 23),
datetime.date(2019, 9, 24),
datetime.date(2019, 9, 25),
datetime.date(2019, 9, 26),
datetime.date(2019, 9, 27),
datetime.date(2019, 9, 28),
datetime.date(2019, 9, 29),
],
[
datetime.date(2019, 9, 30),
datetime.date(2019, 10, 1),
datetime.date(2019, 10, 2),
datetime.date(2019, 10, 3),
datetime.date(2019, 10, 4),
datetime.date(2019, 10, 5),
datetime.date(2019, 10, 6),
],
], [[
datetime.date(2019, 9, 30),
datetime.date(2019, 10, 1),
datetime.date(2019, 10, 2),
datetime.date(2019, 10, 3),
datetime.date(2019, 10, 4),
datetime.date(2019, 10, 5),
datetime.date(2019, 10, 6),
], [
datetime.date(2019, 10, 7),
datetime.date(2019, 10, 8),
datetime.date(2019, 10, 9),
datetime.date(2019, 10, 10),
datetime.date(2019, 10, 11),
datetime.date(2019, 10, 12),
datetime.date(2019, 10, 13),
], [
datetime.date(2019, 10, 14),
datetime.date(2019, 10, 15),
datetime.date(2019, 10, 16),
datetime.date(2019, 10, 17),
datetime.date(2019, 10, 18),
datetime.date(2019, 10, 19),
datetime.date(2019, 10, 20),
], [
datetime.date(2019, 10, 21),
datetime.date(2019, 10, 22),
datetime.date(2019, 10, 23),
datetime.date(2019, 10, 24),
datetime.date(2019, 10, 25),
datetime.date(2019, 10, 26),
datetime.date(2019, 10, 27),
], [
datetime.date(2019, 10, 28),
datetime.date(2019, 10, 29),
datetime.date(2019, 10, 30),
datetime.date(2019, 10, 31),
datetime.date(2019, 11, 1),
datetime.date(2019, 11, 2),
datetime.date(2019, 11, 3),
]]], [[[
datetime.date(2019, 10, 28),
datetime.date(2019, 10, 29),
datetime.date(2019, 10, 30),
datetime.date(2019, 10, 31),
datetime.date(2019, 11, 1),
datetime.date(2019, 11, 2),
datetime.date(2019, 11, 3),
], [
datetime.date(2019, 11, 4),
datetime.date(2019, 11, 5),
datetime.date(2019, 11, 6),
datetime.date(2019, 11, 7),
datetime.date(2019, 11, 8),
datetime.date(2019, 11, 9),
datetime.date(2019, 11, 10),
], [
datetime.date(2019, 11, 11),
datetime.date(2019, 11, 12),
datetime.date(2019, 11, 13),
datetime.date(2019, 11, 14),
datetime.date(2019, 11, 15),
datetime.date(2019, 11, 16),
datetime.date(2019, 11, 17),
], [
datetime.date(2019, 11, 18),
datetime.date(2019, 11, 19),
datetime.date(2019, 11, 20),
datetime.date(2019, 11, 21),
datetime.date(2019, 11, 22),
datetime.date(2019, 11, 23),
datetime.date(2019, 11, 24),
], [
datetime.date(2019, 11, 25),
datetime.date(2019, 11, 26),
datetime.date(2019, 11, 27),
datetime.date(2019, 11, 28),
datetime.date(2019, 11, 29),
datetime.date(2019, 11, 30),
datetime.date(2019, 12, 1),
]], [
[
datetime.date(2019, 11, 25),
datetime.date(2019, 11, 26),
datetime.date(2019, 11, 27),
datetime.date(2019, 11, 28),
datetime.date(2019, 11, 29),
datetime.date(2019, 11, 30),
datetime.date(2019, 12, 1),
],
[
datetime.date(2019, 12, 2),
datetime.date(2019, 12, 3),
datetime.date(2019, 12, 4),
datetime.date(2019, 12, 5),
datetime.date(2019, 12, 6),
datetime.date(2019, 12, 7),
datetime.date(2019, 12, 8),
],
[
datetime.date(2019, 12, 9),
datetime.date(2019, 12, 10),
datetime.date(2019, 12, 11),
datetime.date(2019, 12, 12),
datetime.date(2019, 12, 13),
datetime.date(2019, 12, 14),
datetime.date(2019, 12, 15),
],
[
datetime.date(2019, 12, 16),
datetime.date(2019, 12, 17),
datetime.date(2019, 12, 18),
datetime.date(2019, 12, 19),
datetime.date(2019, 12, 20),
datetime.date(2019, 12, 21),
datetime.date(2019, 12, 22),
],
[
datetime.date(2019, 12, 23),
datetime.date(2019, 12, 24),
datetime.date(2019, 12, 25),
datetime.date(2019, 12, 26),
datetime.date(2019, 12, 27),
datetime.date(2019, 12, 28),
datetime.date(2019, 12, 29),
],
[
datetime.date(2019, 12, 30),
datetime.date(2019, 12, 31),
datetime.date(2020, 1, 1),
datetime.date(2020, 1, 2),
datetime.date(2020, 1, 3),
datetime.date(2020, 1, 4),
datetime.date(2020, 1, 5),
],
]]]
翻译自: https://www.includehelp.com/python/calendar-calendar-yeardatescalendar-method-with-example.aspx
python 示例