Date, Time and Localization Modules

calendar

Works with Gregorian calendar structures, weekdays and leap years. monthrange() returns the weekday of the first day and the number of days in a month; Calendar can generate week layouts. Weekday numbers start at Monday=0; localized labels depend on locale settings. On the tested Python 3.13 runtime, monthrange() returns an integer-compatible Day enum member for the weekday; convert with int() when a plain integer representation is needed.

Formal Syntax & Structure

python syntaxpython
import calendar

Return Value

module

Module namespace available through import; import is a statement, not a value-returning expression.

Working Example

Example Snippetpython
import calendarweekday, days = calendar.monthrange(2024, 2)print(calendar.isleap(2024))print(weekday.name, int(weekday), days)
Python Reference