Python Glossary Русский

all Python 3calendarfunction

calendar.leapdays()

dates and leap years

Counts the leap years in the half-open range [y1, y2) — the second year is not included.

Syntax

calendar.leapdays(y1, y2)

The bound works like range(): leapdays(2000, 2024) is 6, not 7 — 2024 is not counted. To include the last year, pass y2 + 1. Swapping the arguments raises no error: the function returns a negative number.

Examples

import calendar
print(calendar.leapdays(2000, 2024), calendar.leapdays(2000, 2025))  # → 6 7
print(calendar.leapdays(2024, 2000))  # → -6

See also

Open in the full glossarydocs.python.orgReport an inaccuracy