itermonthdays4() : Returns an Iterator of tuples having day , month year and week day for the month.
Week day number starts from 0 as Monday , 1 as Tuesday and ends at 6 as Sunday.
Note that tuple will be returned per the days for the week starting from Previous month and for days for the week extended up to next month. Year is our first or 0th element of the tuple. Month is the second element and day is the third element of the tuples. Week day is 4th element of the tuple
import calendar
my_cal= calendar.Calendar()
for x in my_cal.itermonthdays4(2020,7):
print(x)
As we are getting tuple as output, we can get first element as year , 2nd as month and 3rd as day the month. 4th element is week day in number
import calendar
my_cal= calendar.Calendar(firstweekday=3)
for x in my_cal.itermonthdays4(2020,7):
print('Year:',x[0],', Month : ',x[1],', Day : ',x[2],', Week Day : ',x[3])
Output
Year: 2020 , Month : 6 , Day : 25 Week Day : 3
Year: 2020 , Month : 6 , Day : 26 Week Day : 4
Year: 2020 , Month : 6 , Day : 27 Week Day : 5
Year: 2020 , Month : 6 , Day : 28 Week Day : 6
Year: 2020 , Month : 6 , Day : 29 Week Day : 0
Year: 2020 , Month : 6 , Day : 30 Week Day : 1
Year: 2020 , Month : 7 , Day : 1 Week Day : 2
-------------------------------------------------
-------------------------------------------------
-------------------------------------------------
Year: 2020 , Month : 7 , Day : 29 Week Day : 2
Year: 2020 , Month : 7 , Day : 30 Week Day : 3
Year: 2020 , Month : 7 , Day : 31 Week Day : 4
Year: 2020 , Month : 8 , Day : 1 Week Day : 5
Year: 2020 , Month : 8 , Day : 2 Week Day : 6
Year: 2020 , Month : 8 , Day : 3 Week Day : 0
Year: 2020 , Month : 8 , Day : 4 Week Day : 1
Year: 2020 , Month : 8 , Day : 5 Week Day : 2