The Python calendar library has a function exactly for finding the total number of leap days in the years within range. The calender.leapdays(y1, y2) returns the total number of leap days in the years within range(y1,y2).
For example
import calendar print(calendar.leapdays(1995, 2018))
Output
This will give the output −
6