This itermonthdates()
method from the calendar module extracts the days of a month iterator. It returns an iterator of the month (January to December) which allows extracting days before and after a month to complete a week.
Month iterator returns days as
datetime.date
objects.
itermonthdates(year, month)
It takes the following two parameters:
year
: The year of the calendar.month
: The month of the calendar.It returns an iterator for month
.
Now, let’s discuss the itermonthdates()
method with examples:
# Example#1# loading Calender class from calender modulefrom calendar import Calendarobj = Calendar()# iterating with itermonthdatesmonthIterator = obj.itermonthdates(2021, 1)# printing days in monthfor day in monthIterator:print(day)
itermonthdates()
function with year=2021 and month=1 to extract the month iterator in the monthIterator
variable.for
loop to extract days in the monthIterator
iterator. Then, we print each date on the console.