all Python 3calendarfunction
calendar.setfirstweekday()
first weekday
Sets the global first weekday for the module-level functions: month(), monthcalendar(), weekheader(), prcal() and the rest.
Syntax
calendar.setfirstweekday(firstweekday)
The setting changes for the whole process, not for a single call — it is often cleaner to create your own TextCalendar(firstweekday=6). Class instances and weekday() ignore it: weekday() always counts Monday as zero. A number outside 0–6 raises IllegalWeekdayError; write calendar.SUNDAY for Sunday, not 7.
Examples
import calendar
calendar.setfirstweekday(calendar.SUNDAY)
print(calendar.weekheader(2)) # → Su Mo Tu We Th Fr Sa
print(calendar.monthcalendar(2024, 2)[0]) # → [0, 0, 0, 0, 1, 2, 3]
print(calendar.Calendar().firstweekday) # → 0 — экземпляр не затронут
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy