w3resource

Python TextCalendar Module: leapdays() method

leapdays() method

The leapdays() method is used to get the number of leap years in a specified range of years.
This function works for ranges spanning a century change.

Syntax:

leapdays(y1, y2)

Parameters:

Name Description Required /
Optional
Type
y1, y2 y1 and y2 are years to get the number of leap years. Required Number

Example of leapdays() method

import calendar
print(calendar.leapdays(2015, 2018))

Output:

1

Previous: isleap()
Next: weekday()

Test your Python skills with w3resource's quiz



Python: Tips of the Day

How to make a chain of function decorators?

from functools import wraps

def makebold(fn):
    @wraps(fn)
    def wrapped(*args, **kwargs):
        return "<b>" + fn(*args, **kwargs) + "</b>"
    return wrapped

def makeitalic(fn):
    @wraps(fn)
    def wrapped(*args, **kwargs):
        return "<i>" + fn(*args, **kwargs) + "</i>"
    return wrapped

@makebold
@makeitalic
def hello():
    return "hello world"

@makebold
@makeitalic
def log(s):
    return s

print hello()        # returns "<b><i>hello world</i></b>"
print hello.__name__ # with functools.wraps() this returns "hello"
print log('hello')   # returns "<b><i>hello</i></b>"

Ref: https://bit.ly/3cVz5iw