

- 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 -(monthrange(), prcal(), weekday()?)
We are going to explore different methods of calendar module in this tutorial. Let's see one by one.
calendar.monthrange(year, month)
The method calendar.monthrange(year, month) returns starting weekday number and number of days of the given month. It returns two values in a tuple. Let's see one example.
Example
# importing the calendar module import calendar # initializing year and month year = 2019 month = 1 # getting the tuple of weekday and no. of days weekday, no_of_days = calendar.monthrange(year, month) print(f'Weekday number: {weekday}') print(f'No. of days: {no_of_days}')
Output
If you run the above code, you will get the following results.
Weekday number: 1 No. of days: 31
calendar.prcal(year)
The method calendar.prcal(year) prints the calendar of the year without print function.
Example
# importing the calendar module import calendar # initializing year year = 2019 # printing the calendar using prcal() method calendar.prcal(year)
Output
If you run the above program, you will get the following results.
calendar.weekday(year, month, day)
The method calendar.weekday(year, month, day) takes three arguments and returns the weekday number.
Example
# importing the calendar module import calendar # initializing year, month and day year = 2020 month = 1 day = 28 # getting weekday print(calendar.weekday(year, month, day))
Output
If you run the above code, you will get the following results.
1
Conclusion
If you have any doubts in the tutorial, mention them in the comment section.
- Related Questions & Answers
- Calendar Functions in Python - ( calendar(), month(), isleap()?)
- Calendar Functions in Python | Set 1( calendar(), month(), isleap()…)
- Calendar Functions in Java
- Calendar in python
- What is weekday() method in python?
- Calendar function in Python
- Calendar in Python Program
- Explain calendar module in python?
- Print a Calendar in Python
- Python - Get the weekday from Timestamp object in Pandas
- What is calendar module in python?
- Display weekday names in Java
- The calendar Module in Python
- Getting calendar for a month in Python
- How to Display Calendar using Python?
Advertisements