Python日历库具有恰好可以查找范围内年份中of日总数的功能。calender.leapdays(y1,y2)返回年份范围内(y1,y2)的leap日总数。
import calendar print(calendar.leapdays(1995, 2018))
输出结果
这将给出输出-
6