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.
calendar.leapdays() is a function provided in calendar module for simple text calendars.
leapdays() method is used to get number of leap years in a specified range of years.
Syntax: leapdays() Parameter: year1, year2: years to get the number of leap years. Returns: Returns number of leap years in a specified range.
Code #2: Explaining working of
Below code prints number of leap years and 1st-month calendar of last leap year if any leap year found in given range, otherwise notifies no year is leap.
Number of leap years found is 5 January 2024 Mo Tu We Th Fr Sa Su 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.