In this article, we are going to learn How to check Leap Year in Python if a given year is Leap Year or not in Python. We will ask the user to enter the year and then we will check this input year value. If this is a leap year or not we will print a message on the screen.
We will make use of simple if and else condition in Python.
- 6 ways to get current Timestamp in Python
- How to convert DateTime to string in Python
- How to convert string to datetime in Python
- Unix Timestamp to datetime in Python
- Get the Current Year, month Python
- Get the Current Time in Python
- Convert Date Time to String with Milliseconds
- Convert Epoch to Datetime in Python
- Convert Datetime to Epoch Python
- Get the Current Date in Python
- Get the Day of the Week in Python
- Convert datetime to string in Python
- Compare Two Dates in Python
- Calculate Time Difference Between Time Strings
- Convert date to datetime in Python
- Get the Time zones List Using Python
Python Program to check Leap year
Program Code Explanation –
- Take one variable year and store the value entered by the user. Int is used to convert the value entered by the user to integer or for integer type value and the input() function is used for taking the value from the user.
- If a year is divided by 400 or 4 and the remainder is equal to 0 and divided by 100 reminders is not equal to 0 then print the year as a leap year.
- Else the year is not a leap year.
year = int(input("Enter Year:")) if(year % 400 == 0) or (year % 100! == 0) and (year % 4 == 0): print(year," is Leap Year") else: print(year," is not a Leap Year")
Enter Year:2000 2000 is Leap Year Enter Year:2001 2001 is not a Leap Year