Python calendar module | isleap() method

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python program to explain working of isleap() method
  
# importing calendar module
import calendar
  
# checking whether given year is leap or not
print(calendar.isleap(2016))
print(calendar.isleap(2001))

chevron_right


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.

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python code to demonstrate the working of isleap() 
  
# importing calendar module for calendar operations 
import calendar 
  
year = 2017
  
# calling isleap() method to verify
val = calendar.isleap(year)
  
# checking the condition is True or not
if val == True:
  
    # print 4th month of given leap year 
    calendar.prmonth(year, 4, 2, 1
  
# Returned False, year is not a leap
else:
    print("% s is not a leap year" % year)

chevron_right


Output:

2017 is not a leap year


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.