ADVERTISEMENT
ADVERTISEMENT

Python calendar Module | isleap() Method with Example

Python calendar.isleap() Method: Here, we are going to learn about the isleap() method of calendar module in Python with its definition, syntax, and examples.
Submitted by Hritika Rajput, on May 07, 2020

Python calendar.isleap() Method

isleap() method is an inbuilt method of the calendar module in Python. It works on simple text calendars and checks whether the given year is a leap or not. It returns true if the year is leap else returns false.

Module:

    import calendar

Syntax:

    isleap(year)

Parameter(s):

  • year: the year to be checked

Return value:

The function returns true or false based on whether the year is leap or not.

Example:

# Python program to illustrate the 
# use of isleap() method
  
# importing calendar module 
import calendar 
  
print("Is year 2020 a leap year:", calendar.isleap(2020))
print()

print("Is year 1993 a leap year:", calendar.isleap(1993))
print()

# Print leap if year is a leap year else print not leap
x = calendar.isleap(1234)
if x == True:
    print("leap")
else:
    print("not leap")

Output

Is year 2020 a leap year: True

Is year 1993 a leap year: False

not leap

Example:

# Python program to illustrate the 
# use of isleap() method

# Printing leap years between a range  

# importing calendar module 
import calendar 

print("Leap years between 1900 to 2000...")  
for year in range(1900, 2000+1):
  if calendar.isleap(year):
    print(year)

Output

Leap years between 1900 to 2000...
1904
1908
1912
1916
1920
1924
1928
1932
1936
1940
1944
1948
1952
1956
1960
1964
1968
1972
1976
1980
1984
1988
1992
1996
2000
ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.