calendar.monthrange()
calendar.monthrange() is a Python function in the Calendar Module category. Returns (weekday_of_first_day, number_of_days) for a given month. The syntax is calendar.monthrange(year, month). Returns: (int, int) tuple. A typical example: calendar.monthrange(2026, 2) # (6, 28) — Feb 2026 starts Saturday, 28 days. A close sibling is calendar.TextCalendar(), which creates a calendar that generates plain text calendars. A close sibling is calendar.HTMLCalendar(), which creates a calendar that generates HTML calendars. A close sibling is calendar.isleap(), which returns True if the year is a leap year. A close sibling is calendar.leapdays(), which returns the number of leap years in the range [y1, y2). More about this category: Calendar functions — TextCalendar, isleap, monthrange, weekday. For a broader walkthrough, read the Calendar Module guide. Related Calendar Module entries: calendar.TextCalendar(), calendar.HTMLCalendar(), calendar.isleap(), calendar.leapdays(), calendar.weekday(), calendar.day_name. This page is part of the free Python Reference documentation covering 978+ functions, methods, and modules with examples and parameter details.