- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to get the total number of leap days in the years within range in Python?
In this article we will discuss how to find the number of leap years in a specified ranges of year in python.
leapdays()
The calendar module offers more helpful calendar-related tasks in addition to allowing calendars to be produced like programmes. The idealised calendar used by the functions and classes defined in the Calendar module is the present Gregorian calendar stretched indefinitely in both directions.
For simple text calendars, the calendar module in Python provides the function calendar.leapdays().
Syntax
the syntax of the leapdays() method is as follows.
leapdays()
The above function takes two parameters; they are −
- year1: This represents the initial year for the range.
- year2: This represents the final year or the end of the range.
Returns
The leapdays() function takes the above parameters and return the number of leap year in a specified range of years.
Example
In the following example code, we find the number of leap days in the specified range of years is achieved using the leapdays() function which is provided by the calender module in python.
import calendar print("The number of leapdays in the range of 2011 to 2030 is:") print(calendar.leapdays(2011, 2030)) print("The number of leapdays in the range of 2001 to 2100 is:") print(calendar.leapdays(2001, 2100))
Output
The output of the above code is as follows.
The number of leapdays in the range of 2011 to 2030 is: 5 The number of leapdays in the range of 2001 to 2100 is: 24
- Related Articles
- Write a program in Python to count the total number of leap years in a given DataFrame
- Python Pandas - Get the total number of days of the month that the Period falls in
- Write a Python function to calculate the total number of business days from a range of start and end date
- Finding nth day of the year in leap and non-leap years in JavaScript
- C++ Program to calculate the number of odd days in given number of years
- Python Pandas - Get the number of days from TimeDelta
- Program to find number of pairs where elements square is within the given range in Python
- How to get the number of days between two Dates in JavaScript?
- Program to convert given number of days in terms of Years, Weeks and Days in C
- Python - Find the number of prime numbers within a given range of numbers
- How to calculate the possibilities of duplication for random number within a range in Java
- How to get days, months and years between two Java LocalDate?
- Armstrong number within a range in JavaScript
- Capacity To Ship Packages Within D Days in Python
- Finding next n leap years in JavaScript
