w3resource

Python Calendar Module: monthdays2calendar() method

monthdays2calendar() method

The monthdays2calendar() method is used to get a list of the weeks in the month of the year as full weeks. Weeks are lists of seven-tuples of day numbers and weekday numbers.

Syntax:

monthdays2calendar(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 monthdatescalendar() method

import calendar
cal= calendar.Calendar()
print(cal.monthdays2calendar(2016, 5))

Output:

[[(0, 0), (0, 1), (0, 2), (0, 3), (0, 4), (0, 5), (1, 6)], [(2, 0), (3, 1), (4, 2), (5, 3), (6, 4), (7, 5), (8, 6)], [(9, 0), (10, 1), (11, 2), (12, 3), (13, 4), (14, 5), (15, 6)], [(16, 0), (17, 1), (18, 2), (19, 3), (20, 4), (21, 5), (22, 6)], [(23, 0), (24, 1), (25, 2), (26, 3), (27, 4), (28, 5), (29, 6)], [(30, 0), (31, 1), (0, 2), (0, 3), (0, 4), (0, 5), (0, 6)]]

Previous: monthdatescalendar()
Next: monthdayscalendar()

Test your Python skills with w3resource's quiz



Follow us on Facebook and Twitter for latest update.