w3resource

Python TextCalendar Module : isleap() method

isleap() method

The isleap() method returns True if the year is a leap year, otherwise False.

Note : A leap year is a year containing one additional day added to keep the calendar year synchronized with the astronomical or seasonal year.

Syntax:

isleap(year)

Parameters:

Name Description Required /
Optional
Type
year Year to test leap year or not. Required Number

Example - 1: isleap() method

import calendar
print(calendar.isleap(2016))

Output:

True

Example -2: isleap() method

import calendar
print(calendar.isleap(2015))

Output:

False

Previous: firstweekday()
Next: leapdays()

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