Reference · Dates
date.is_leap_year
signature
date.is_leap_year(int | str) -> boolWhat it does
Whether a year has a 29th of February: true for years divisible by 4, except
centuries, except those divisible by 400 (the Gregorian rule). It takes the year as an
int, or a date or date-time, whose year it uses.
Examples
print(date.is_leap_year(2024), date.is_leap_year(2023))print(date.is_leap_year(1900), date.is_leap_year(2000))print(date.is_leap_year("2024-06-01"))output
true falsefalse truetrueEdge cases
- A date-time's year is read as written, like a date's.
- An int is not checked against the calendar's range: 0 and negative years answer by the same rule. A float with a whole value is taken as an int.
print(date.is_leap_year("2024-12-31T23:00:00-05:00"))print(date.is_leap_year(0), date.is_leap_year(-4), date.is_leap_year(2024.0))output
truetrue true trueErrors
A string that is not a date, or a value that is neither an int nor a string, is a runtime error, not an error value.
this one fails
print(date.is_leap_year("2024"))output
line 1: `date.is_leap_year` expects a date or a date-time as argument 1, got "2024"Chaining
print(range(2023, 2029) | filter(date.is_leap_year))print("2024-02-10" | date.is_leap_year)output
[2024, 2028]trueSee also
date.days_in_month, date.parts, date.add_years, date.end_of_month
Thread
Thread 0 posts
On date.is_leap_year(): questions, tips, corrections, and code that uses it.
No posts yet. The first one opens the thread.
Edit this page on GitHub · every example's output was made by running it (tools/refcheck.mjs) · questions on Discord or r/quillo