在Python中,你可以使用`calendar`模块中的`isleap()`函数来判断一个年份是否是闰年。这个函数接受一个参数——年份,如果该年份是闰年,则返回`True`,否则返回`False`。
下面是一个使用`isleap()`函数判断闰年的示例代码:
import calendar
def is_leap_year(year):
return calendar.isleap(year)
year = 2020
if is_leap_year(year):
print(year, "is a leap year")
else:
print(year, "is not a leap year")
运行上述代码,会输出“2020 is a leap year”,因为2020年是闰年。