Python - itermonthdays2()


Python tip:

To get a date and a day in a week for a specific month, you can use the itermonthdays2 method.

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

Day numbers outside this month are zero.

import calendar

cal = calendar.Calendar()
days = cal.itermonthdays2(2022, 7)

for day in days:
    print(day)

"""
Results:

(0, 0)
(0, 1)
(0, 2)
(0, 3)
(1, 4)
(2, 5)
(3, 6)

...

(29, 4)
(30, 5)
(31, 6)
"""