Home »
Python »
Python Reference »
Python Calendar class
Python Calendar itermonthdays3() Method with Example
Python Calendar.itermonthdays3() Method: In this tutorial, we will learn about the itermonthdays3() method of Calendar class in Python with its usage, syntax, and examples.
By Hritika Rajput Last updated : April 24, 2023
Python Calendar.itermonthdays3() Method
The Calendar.itermonthdays3() method is an inbuilt method of the Calendar class of the calendar module, it returns an iterator for the given month in the given year. The month consists of full weeks, i.e., each week has full 7 values even if the value is outside of the month. An entry in a week is given by a tuple consisting of a year, a month, and a day of the month numbers.
Module
The following module is required to use itermonthdays3() method:
import calendar
Class
The following class is required to use itermonthdays3() method:
from calendar import Calendar
Syntax
The following is the syntax of itermonthdays3() method:
itermonthdays3(year, month)
Parameter(s)
The following are the parameter(s):
- year: It is a required parameter, which specifies the year of the calendar.
- month: It is a required parameter, which specifies the month of the calendar.
Return Value
The return type of this method is <class 'generator'>, it returns an iterator for the month where each value is a tuple consisting of the year, month and date on that day.
Example of Calendar.itermonthdays3() Method in Python
# Python program to illustrate the
# use of itermonthdays3() method
# import class
import calendar
# Creating Calendar Instance
cal = calendar.Calendar()
year = 2019
month = 12
print("Iterating over the weeks of December 2019 where each tuple is date, month and year")
for i in cal.itermonthdays3(year, month):
print(i)
# first value is the day of the month;
# days outside of the month is 0
# second value is weekday number where
# Monday is 0 till Sunday which is 6
print()
print()
# set the firstweekday to 1
cal = calendar.Calendar(firstweekday = 1)
year = 1994
month = 9
print("Iterating over the weeks of September 1994 where each tuple is date, month and year and iterator starts with firstweekday as Tuesday")
for i in cal.itermonthdays3(year, month):
print(i)
print()
print()
Output
Iterating over the weeks of December 2019 where each tuple is date, month and year
(2019, 11, 25)
(2019, 11, 26)
(2019, 11, 27)
(2019, 11, 28)
(2019, 11, 29)
(2019, 11, 30)
(2019, 12, 1)
(2019, 12, 2)
(2019, 12, 3)
(2019, 12, 4)
(2019, 12, 5)
(2019, 12, 6)
(2019, 12, 7)
(2019, 12, 8)
(2019, 12, 9)
(2019, 12, 10)
(2019, 12, 11)
(2019, 12, 12)
(2019, 12, 13)
(2019, 12, 14)
(2019, 12, 15)
(2019, 12, 16)
(2019, 12, 17)
(2019, 12, 18)
(2019, 12, 19)
(2019, 12, 20)
(2019, 12, 21)
(2019, 12, 22)
(2019, 12, 23)
(2019, 12, 24)
(2019, 12, 25)
(2019, 12, 26)
(2019, 12, 27)
(2019, 12, 28)
(2019, 12, 29)
(2019, 12, 30)
(2019, 12, 31)
(2020, 1, 1)
(2020, 1, 2)
(2020, 1, 3)
(2020, 1, 4)
(2020, 1, 5)
Iterating over the weeks of September 1994 where each tuple is date, month and year and iterator starts with firstweekday as Tuesday
(1994, 8, 30)
(1994, 8, 31)
(1994, 9, 1)
(1994, 9, 2)
(1994, 9, 3)
(1994, 9, 4)
(1994, 9, 5)
(1994, 9, 6)
(1994, 9, 7)
(1994, 9, 8)
(1994, 9, 9)
(1994, 9, 10)
(1994, 9, 11)
(1994, 9, 12)
(1994, 9, 13)
(1994, 9, 14)
(1994, 9, 15)
(1994, 9, 16)
(1994, 9, 17)
(1994, 9, 18)
(1994, 9, 19)
(1994, 9, 20)
(1994, 9, 21)
(1994, 9, 22)
(1994, 9, 23)
(1994, 9, 24)
(1994, 9, 25)
(1994, 9, 26)
(1994, 9, 27)
(1994, 9, 28)
(1994, 9, 29)
(1994, 9, 30)
(1994, 10, 1)
(1994, 10, 2)
(1994, 10, 3)