This post shows how to check whether a given year is a leap year in Python, using the standard leap year rule.
Check leap year in Python:
Explanation:
A year is a leap year if it's divisible by 4, except for century years (divisible by 100), which must also be divisible by 400 to qualify. This is why 2000 was a leap year but 1900 was not.
Python Program to Check Leap Year
year = int(input("Enter a year: "))
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
print(f"{year} is a leap year")
else:
print(f"{year} is not a leap year")
Output:
Enter a year: 2024
2024 is a leap year
Conditional logic like this is a common building block in interview questions — see more in our Interview Prep section.
