Python - itermonthdays4()


Python tip:

To get complete dates (including a day in a week) for a certain month, you can use the itermonthdays4 method.

Returned days will be tuples, consisting of a year, a month, a day of the month, and a week day number.

import calendar

cal = calendar.Calendar()
days = cal.itermonthdays4(2022, 2)

for day in days:
    print(day)

"""
Results:

(2022, 1, 31, 0)
(2022, 2, 1, 1)
(2022, 2, 2, 2)
(2022, 2, 3, 3)

...

(2022, 3, 4, 4)
(2022, 3, 5, 5)
(2022, 3, 6, 6)
"""