Python Glossary Русский

all Python 3calendarterm

calendar

module

Calendars and date helpers: leap years, weekdays and the grid of a month.

Syntax

import calendar

It answers calendar questions: whether a year is leap, how many days a month has, which weekday a date falls on, how to print a month as text or HTML. Dates themselves and date arithmetic come from datetime, while calendar handles laying them out in weeks. Note that weeks start on Monday by default and weekdays are numbered from 0.

Examples

import calendar
print(calendar.isleap(2024))  # → True
print(calendar.monthrange(2024, 2)[1])  # → 29 — дней в феврале 2024
print(calendar.weekday(2024, 1, 1))  # → 0

See also

Open in the full glossarydocs.python.orgReport an inaccuracy