
Python calendar: How to check if this year is leap year in Python
In Python, we can easily check if a year is leap or not importing calendar and using function isleap
.
import calendar
i = calendar.isleap(2016)
print(i) # True
i = calendar.isleap(2020)
print(i) # True
i = calendar.isleap(2019)
print(i) # False
i = calendar.isleap(2000)
print(i) # True
i = calendar.isleap(2100)
print(i) # False
2020 is leap year but 2019 is not.
Comments
Powered by Markdown