Python Glossary Русский

Python 3.12+calendarterm

calendar.Day

days and months

An enumeration of weekdays (IntEnum) from MONDAY = 0 to SUNDAY = 6; its members are also exposed as calendar.MONDAY…calendar.SUNDAY.

Syntax

calendar.Day.MONDAY  # … calendar.Day.SUNDAY

Numbering starts at zero on Monday: Sunday is 6, whereas date.isoweekday() counts Monday as 1 and Sunday as 7. calendar.MONDAY and friends are the very same objects as Day.MONDAY (an is check gives True), and since 3.12 weekday() and monthrange() return Day members. It is an IntEnum, so comparing with integers and indexing still work; on 3.11 there is no Day and MONDAY is just 0.

Examples

import calendar
d = calendar.weekday(2024, 10, 7)
print(d == calendar.Day.MONDAY, d.name)  # → True MONDAY
print(calendar.Day.SUNDAY.value)  # → 6
print(calendar.MONDAY is calendar.Day.MONDAY)  # → True
import calendar, datetime
day = datetime.date(2024, 10, 13)
print(day.weekday(), day.isoweekday())  # → 6 7 — воскресенье

See also

Open in the full glossarydocs.python.orgReport an inaccuracy