all Python 3calendarfunction
calendar.month()
printing calendars
Returns a calendar of one month as a multi-line string, like TextCalendar.formatmonth().
Syntax
calendar.month(theyear, themonth, w=0, l=0)
The function returns a string; prmonth() is the one that prints. The first weekday comes from the global setfirstweekday(), the names from the process locale (English until locale.setlocale is called). On 3.11 and early 3.12 month(2024, 13) failed with IndexError, in newer versions with IllegalMonthError; except ValueError catches only the latter, so validate the month beforehand.
Examples
import calendar
text = calendar.month(2024, 2)
print(text.splitlines()[1]) # → Mo Tu We Th Fr Sa Su
print(text.splitlines()[-1]) # → 26 27 28 29
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy