importcalendar
year=2019
ifcalendar.isleap(year):
day_num=365
else:
day_num=366
calendar库中的闰年算法
defisleap(year):
"""ReturnTrueforleapyears,Falsefornon-leapyears."""
returnyear%4==0and(year%100!=0oryear%400==0)