On this page
  1. calendar.monthrange
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

calendar.monthrange

Prev: calendar.monthcalendar | Up: calendar | Next: calendar.prcal
Rel: calendar.calendar, calendar.Calendar, calendar.Day, calendar.firstweekday
Ref: docs.python.org — calendar.monthrange
Tags: #public #python3 #stdlib #calendar


Import

import calendar
from calendar import monthrange

Signature & Overview

calendar.monthrange(year, month)

Return weekday of first day of month (0-6 ~ Mon-Sun) and number of days (28-31) for year, month.

Usage

import calendar

first_wday, num_days = calendar.monthrange(2026, 2)
assert num_days == 28 and first_wday in range(7)

Gotchas

REPL Inspect

from calendar import monthrange
help(monthrange)

Linked from

Related notes