The calendar module turns years and months into week layouts, names, and text or HTML representations. It fits user interfaces and reports, while datetime remains the foundation for representing dates.

Build the weeks in a month

import calendar

weeks = calendar.monthcalendar(2026, 10)
for week in weeks:
    print(week)

assert calendar.isleap(2024)

Understand zeros and first weekdays

Each week contains seven integers. Zero marks a position outside the selected month. Weeks start on Monday by default; prefer a Calendar(firstweekday=...) instance over changing global state with setfirstweekday().

Separate display from rules

Use month_name, day_name, TextCalendar, or HTMLCalendar for presentation. For deadlines, time zones, and instants, use date objects and explicit policies. Test year boundaries and leap years.

Keep learning

Continue with dates and times with datetime. The official Python documentation, accessed July 22, 2026, covers iterators, formatting, and conventions.