

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Calendar Functions in Python - ( calendar(), month(), isleap()?)
We can perform the calendar operations using the calendar module in Python. Here, we are going to learn about the different methods of calendar class instance.
calendar.calendar(year)
The calendar class instance returns the calendar of the year. Let's see one example.
Example
# importing the calendar module import calendar # initializing year year = 2019 # printing the calendar print(calendar.calendar(year))
Output
If you run the above code, you will get the following results.
calendar.firstweekday()
The method calendar.firstweekday() returns the first weekday in the week i.e.., MONDAY.
Example
# importing the calendar import calendar # getting firstweekday of the year print(calendar.firstweekday())
Output
If you run the above program, you will get the following results.
0
calendar.isleap(year)
The method calendar.isleap(year) returns whether the year is a leap or not. Let's take one example.
Example
# importing the calendar module import calendar # initializing years year_one = 2019 year_two = 2020 # checking whether they are leap or not print(f'{year_one} is leap year' if calendar.isleap(year_one) else f'{year_one} is not a leap year') print(f'{year_two} is leap year' if calendar.isleap(year_two) else f'{year_two} is not a leap year')
Output
If you run the above code, you will get the following results.
2019 is not a leap year 2020 is leap year
calendar.WEEK_CONSTANT
There are WEEK_CONSTANTS in the calendar module to get the weekday number. Let's see examples.
Example
# importing the calendar module import calendar # getting weekday numbers print(f'Monday weekday: {calendar.MONDAY}') print(f'Tuesday weekday: {calendar.TUESDAY}') print(f'Wednesday weekday: {calendar.WEDNESDAY}') print(f'Thursday weekday: {calendar.THURSDAY}') print(f'Friday weekday: {calendar.FRIDAY}') print(f'Saturday weekday: {calendar.SATURDAY}') print(f'Sunday weekday: {calendar.SUNDAY}')
Output
If you run the above program, you will get the following results.
Monday weekday: 0 Tuesday weekday: 1 Wednesday weekday: 2 Thursday weekday: 3 Friday weekday: 4 Saturday weekday: 5 Sunday weekday: 6
Conclusion
We have learned some useful methods in this tutorial. If you have any queries regarding the tutorial, mention them in the comment section.
- Related Questions & Answers
- Calendar Functions in Python | Set 1( calendar(), month(), isleap()…)
- Calendar Functions in Java
- Getting calendar for a month in Python
- Calendar Functions in Python -(monthrange(), prcal(), weekday()?)
- Calendar in python
- How to print calendar for a month in Python?
- Display Month of Year using Java Calendar
- Calendar function in Python
- Calendar in Python Program
- Increment a Month using the Calendar Class in Java
- Decrement a Month using the Calendar Class in Java
- Explain calendar module in python?
- Print a Calendar in Python
- Get week of month and year using Java Calendar
- What is calendar module in python?