Home »
Python »
Python Reference »
Python Calendar class
Python Calendar yeardatescalendar() Method with Example
Python Calendar.yeardatescalendar() Method: In this tutorial, we will learn about the yeardatescalendar() method of Calendar class in Python with its usage, syntax, and examples.
By Hritika Rajput Last updated : April 24, 2023
Python Calendar.yeardatescalendar() Method
The Calendar.yeardatescalendar() method is an inbuilt method of the Calendar class of calendar module, it returns a list of month rows for the given year.
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.
Module
The following module is required to use yeardatescalendar() method:
import calendar
Class
The following class is required to use yeardatescalendar() method:
from calendar import Calendar
Syntax
The following is the syntax of yeardatescalendar() method:
yeardatescalendar(year, width =3)
Parameter(s)
The following are the parameter(s):
- year: It is a required parameter, which specifies the year of the calendar.
- width: It is an optional parameter, which specifies the width of the month value; default value = 3.
Return Value
The return type of this method is <class 'list'>, it returns a list of month rows giving datetime.date objects.
Example of Calendar.yeardatescalendar() Method in Python
# 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 2
# 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),
],
]]]