Calendar module allows to output calendars like program, and provides additional useful functions related to the calendar. Functions and classes defined in Calendar module use an idealized calendar, the current Gregorian calendar extended indefinitely in both directions.
monthdayscalendar() method in Python is used to get a list of the weeks in the month of the year as full weeks.
Syntax: monthdayscalendar(year, month) Parameter: year: year of the calendar month: month of the calendar Returns: a list of the weeks in the month.
Code #1:
# Python program to demonstrate working # of monthdayscalendar() method # importing calendar module import calendar obj = calendar.Calendar() year = 2018mnth = 9 # priting with monthdayscalendar print(obj.monthdayscalendar(year, mnth)) |
Output:
[[0, 0, 0, 0, 0, 1, 2], [3, 4, 5, 6, 7, 8, 9], [10, 11, 12, 13, 14, 15, 16], [17, 18, 19, 20, 21, 22, 23], [24, 25, 26, 27, 28, 29, 30]]
Note that weeks in the output are lists of seven day numbers.
Code #2: iterating the list of weeks
# Python program to demonstrate working # of monthdayscalendar() method # importing calendar module import calendar obj = calendar.Calendar() # iteratign with monthdayscalendar for day in obj.monthdayscalendar(2018, 9): print(day) |
Output:
[0, 0, 0, 0, 0, 1, 2] [3, 4, 5, 6, 7, 8, 9] [10, 11, 12, 13, 14, 15, 16] [17, 18, 19, 20, 21, 22, 23] [24, 25, 26, 27, 28, 29, 30]
Recommended Posts:
- Python program to print Calendar without calendar or datetime module
- Calendar Functions in Python | Set 1( calendar(), month(), isleap()...)
- Python calendar module | formatmonth() method
- Python calendar module | itermonthdays2() method
- Python calendar module | iterweekdays() method
- Python calendar module | itermonthdays() method
- Python calendar module | monthdatescalendar() method
- Python calendar module | monthdays2calendar() method
- Python calendar module | yeardatescalendar() method
- Python calendar module | yeardays2calendar() method
- Python calendar module | yeardayscalendar() method
- Python calendar module | itermonthdates() method
- Python calendar module | prmonth() method
- Python calendar module | formatyear() method
- Python calendar module | pryear() method
- Python calendar module | HTMLCalendar formatmonth() method
- Python calendar module | HTMLCalendar formatyear() method
- Python calendar module | HTMLCalendar formatyearpage() method
- Python calendar module | setfirstweekday() method
- Python calendar module | firstweekday() method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

