If you search in internet on how to find whether the given year is leap year in Python, You will get a huge list of websites with article. These articles explains on finding leap with multiple lines of code using the leap-year rule. However, there is a straight forward method in Python to find if the given year is leap or not. The method isleap() in calendar module return True if the given year is leap and False if it is not leap. Let’s see an example.
import calendar for year_i in range(2009,2021): print("Is", year_i, "a leap? ", calendar.isleap(year_i))
- How to identify if the given year is a leap or not in SQL Server?
- Finding the total number of weeks in a month in Python.
- More about calendar.isleap() at Python docs.