Python BasicsEasy

Leap year or not

Detailed guide and Python implementation for the 'Leap year or not' problem.

Problem Statement

Easy

Write a function is_leap_year(year) that takes an integer year and returns True if the year is a leap year, or False otherwise. A year is a leap year if it is divisible by 4 but not by 100, except when it is also divisible by 400.

Constraints
  • 1 <= year <= 10^5

Examples

Example 1
Input
year = 2024
Output
True
Explanation

2024 is divisible by 4 and not by 100, so it is a leap year.

Example 2
Input
year = 1900
Output
False
Explanation

1900 is divisible by 100 but not by 400, so it is not a leap year.

Example 3
Input
year = 2000
Output
True
Explanation

2000 is divisible by 400, so it is a leap year.

Need a Hint?
Consider using Basics-specific data structures like sets or heaps.
Edge Cases to Watch
  • Empty input structures
  • Single element inputs
  • Large numerical bounds

Ready to Solve?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Open in Editor

Recommended Python Resources

Expand your knowledge with related interactive tutorials, cheat sheets, and code comparisons.