Python calendar module | isleap() method
Last Updated :
22 Oct, 2018
Calendar module allows to output calendars like program, and provides additional useful functions related to the calendar. Functions and classes defined in Calendar module use an idealized calendar, the current Gregorian calendar extended indefinitely in both directions.
In Python, calendar.isleap()
is a function provided in calendar module for simple text calendars.
isleap()
method is used to get value True if the year is a leap year, otherwise gives False.
Syntax: isleap()
Parameter:
year: Year to be tested leap or not.
Returns: Returns True if the year is a leap year, otherwise False.
Code #1:
import calendar
print (calendar.isleap( 2016 ))
print (calendar.isleap( 2001 ))
|
Output:
True
False
Code #2: Explaining working of isleap()
method.
Below code prints 4th months calendar if given year is year, otherwise notifies year is not leap.
import calendar
year = 2017
val = calendar.isleap(year)
if val = = True :
calendar.prmonth(year, 4 , 2 , 1 )
else :
print ( "% s is not a leap year" % year)
|
Output:
2017 is not a leap year
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...