Content · Programming · Python

Python calendar.isleap() Function: Usage and Examples

Check whether a Gregorian calendar year has 29 days in February.

2 views Published Oct 17, 2026 Updated Oct 18, 2026 Admin

Check whether a Gregorian calendar year has 29 days in February.

How It Works


calendar.isleap(year) implements Gregorian leap-year rules: years divisible by four are usually leap years, except centuries not divisible by 400.

Step-by-Step Example


import calendar
print(calendar.isleap(2028))
print(calendar.isleap(2100))
print(calendar.isleap(2000))

Understanding the Example


  • The print() call exposes the result so you can compare it with the behavior described above. Check the value and its type when experimenting.

A successful run of this example prints the following output:

True
False
True

Where This Fits in a Real Program


For event timestamps, distinguish the displayed local clock from the instant that it represents. Store or exchange an unambiguous aware value, then convert it when displaying it to a user. For repeated calendar appointments, use a geographic timezone so daylight-saving rules are not lost.

Practice: Try It Yourself


Leap-year rules affect February length, not time-zone offsets.

For this exercise, predict the result before running the changed code. Then explain the difference between the original and modified cases using the actual values, not just whether the program completed.

Further Reading


Read the official Python documentation for complete parameters, return types and exceptions.

Common Beginner Mistakes


  • Treating every year divisible by four as a leap year without the century exception.
  • Write a list of leap years between 2020 and 2040.

Key Takeaways


  • Check whether a Gregorian calendar year has 29 days in February.
  • calendar.isleap(year) implements Gregorian leap-year rules: years divisible by four are usually leap years, except centuries not divisible by 400.
  • Apply the demonstrated operation to the practice input and verify its result before depending on it in a larger program.
Share this resourceSend this page to someone who may find it useful.