Thursday, 14 July 2016

Python: Get leap years in given range

‘calendar.leapdays(y1, y2)’ is used to get number of leap years from year y1 to y2. Years y1 and y2 are exclusive.

>>> import calendar
>>> calendar.leapdays(2000,3000)
243
>>> 
>>> calendar.leapdays(1000,2000)
242
>>> 
>>> calendar.leapdays(0,1000)
243


Previous                                                 Next                                                 Home

No comments:

Post a Comment