这段代码是用于判断年份是否为闰年的语句,根据闰年判断规则分为以下三种情况:
1、能被4整除但不能被100整除的年份是闰年。例如2004年是闰年,1900年不是闰年。 2、能被100整除但同时又能被400整除的年份是闰年。例如2000年是闰年,1900年不是闰年。 3、其他的年份都不是闰年。
以下是Python代码示例:
def is_leap_year(year):
if year % 4 == 0 and (year % 100 != 0 or year % 400 == 0):
return True
else:
return False
print(is_leap_year(2000)) # True
print(is_leap_year(1900)) # False
print(is_leap_year(2021)) # False