import calendar
my_cal= calendar.Calendar(firstweekday=3)
for x in my_cal.monthdayscalendar(2020,7):
print(x)
As we are getting a list as output, we can get total number of weeks in a month and number of days in a week. We are using len() here to get number of elements ( items ) .
import calendar
my_cal= calendar.Calendar(firstweekday=0)
y=my_cal.monthdayscalendar(2020,7)
print("Number of weeks",len(y))
print("Number of days in week",len(y[0]))
Output
Number of weeks 5
Number of days in week 7
As we are getting a list of days as tuple for each week , we can display day and week day number like this.
import calendar
my_cal= calendar.Calendar(firstweekday=0)
for x in my_cal.monthdayscalendar(2020,7):
for y in x:
print("Day :",y)
Output
Day : 0
Day : 0
Day : 1
Day : 2
Day : 3
Day : 4
Day : 5
Day : 6
--------
--------
Day : 26
Day : 27
Day : 28
Day : 29
Day : 30
Day : 31
Day : 0
Day : 0