- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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 in Python Program
Python has a built-in module called calendar to work with calendars. We are going to learn about the calendar module in this article.
The week in the calendar modules starts on Monday and ends on Sunday. The module calendar follows the Gregorian calendar. Let's see some useful methods of the calendar module.
Getting Year Calendar
If you have to get the calendar of the specific year, then create the instance of the class calendar.calendar(year) and print it. Let's see one example.
# importing the calendar module import calendar # initializing the year year = 2019 # printing the calendar print(calendar.calendar(2019))
If you run the above code, you will get the following results.
We can get different types of outputs using the calendar.calendar(year) instance. Try to learn those methods using the dir().
Getting Month Calendar
If you have to get the calendar of the specific month, then use the method calendar.month(year, month_number) and print it. Let's see one example.
# importing the calendar module import calendar # initializing the yearn and month number year = 2000 month = 1 # getting the calendar of the month print(calendar.month(year, month))
If you run the above program, you will get the following results.
January 2000 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
If you are having any trouble following the tutorial, comment below.
- Calendar in python
- Calendar Functions in Python - ( calendar(), month(), isleap()?)
- Calendar function in Python
- Calendar Functions in Python | Set 1( calendar(), month(), isleap()…)
- Explain calendar module in python?
- Print a Calendar in Python
- What is calendar module in python?
- Calendar Functions in Python -(monthrange(), prcal(), weekday()?)
- The calendar Module in Python
- Getting calendar for a month in Python
- How to Display Calendar using Python?
- Gregorian Calendar in Java
- Calendar Functions in Java
- How to print calendar for a month in Python?
- Java Program to subtract 40 days from the calendar