Python TextCalendar Module: monthcalendar() method
monthcalendar() method
The monthrange() method is used to get a matrix representing a month’s calendar.
Each row represents a week; days outside of the month a represented by zeros.
Each week begins with Monday unless set by setfirstweekday().
Syntax:
monthcalendar(year, month)
Parameters:
Name | Description | Required / Optional |
Type |
---|---|---|---|
year | Year for which the calendar should be generated. | Required | Number |
month | Month for which the calendar should be generated. | Required | Number |
Example of monthcalendar() method
import calendar
print(calendar.monthcalendar(2016,5))
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], [31, 0, 0, 0, 0, 0, 0]]
Previous: weekheader()
Next: prmonth()
Test your Python skills with w3resource's quiz
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics