PYTHON EXAMPLE · WORKING REFERENCE

Check a Leap Year

Divisibility rules aur boolean operators se Gregorian leap year check karo.

Working code

year = 2024

is_leap = year % 400 == 0 or (year % 4 == 0 and year % 100 != 0)

if is_leap:
    print("Leap year")
else:
    print("Not a leap year")
Run Code ▶

Expected output

Leap year

How it works

400 se divisible year leap hota hai. Otherwise year ko 4 se divisible aur 100 se not divisible hona chahiye.

Try Yourself

year = 2100
is_leap = year % 400 == 0 or (year % 4 == 0 and year % 100 != 0)
print(is_leap)

Learn this concept

Read related Python Tutorial →