Print a Calendar using Python

The calendar module in Python provides access to the calendar of any month of any year. If you’ve never used this module before, this article is for you. In this article, I will present a tutorial on how to write a program to print a calendar using Python.

Print a Calendar using Python

There are so many useful built-in modules in Python that can be used to fulfil your goal in a few lines of code. One of these modules in Python is the calendar module which provides access to the calendar of any month of any year. Anytime you want to show a calendar to a user, this Python module will come in handy. Now here is how you can easily write a program to print a calendar using Python:

import calendar
print(calendar.month(2021, 9))
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

In the code above, I have first imported the calendar module in Python. Then I have used the print function to print the calendar of September 2021 using the month function of the calendar module. You can also take user input as year and month, then you can use the user inputs as parameters of the month function of the calendar module.

Also, Read – Python projects with Source Code.

Summary

So this is how you can write a program to print the calendar of any month of any year using Python in just a few lines of code. Anytime you want to show a calendar to a user, then the calendar module will come in handy. I hope you liked this article on how to show a calendar using the Python programming language. Feel free to ask your valuable questions in the comments section below.

Default image
Aman Kharwal
Coder with the ♥️ of a Writer || Data Scientist | Solopreneur | Founder
Articles: 1135

Leave a Reply