Python Program to display a calendar of a month

March 17, 2022, Learn eTutorial

In this simple python program, we have to display a calendar of a month. It's a beginner-level python program.

To understand this example, you should have knowledge of the following Python programming topics:

Explain the Calendar Module in python?

To display a calendar, we have a predefined module in python called a calendar, which displays the calendar. The syntax of the calendar module is like (calendar.month(yy,mm)) where'

  • yy is the year
  • mm is the month.

We have many predefined operations on this calendar module in python language. For example,

  • firstweekday(): which returns the first-day number of the week.
  • isleap (year): this is to check the given year is a leap year or not.
  • Leap days (year1, year2): this will return with the number of leap days within a two-year limit.
  • Month (year, month ): this is used in this program, which prints a specific month of a specific year.

There are many more methods to use with the calendar module, which is described in the calendar module tutorial.

How to print a calendar using Python language?

In this simple python program, we accept the values for year and month from the user and import the calendar module. Finally, we call the print function and call the calendar module to print the year and month print(calendar.month(yy,mm)). Let us break the code


STEP 1: Import the python built-in module called calendar, which has many accepted operational methods we discussed above in the description.

STEP 2: Accept the year and month from the user using the input method as a string and convert that to an integer using int in python language.

STEP 3: Just use the operation month(yy, mm) with the calendar module like a calendar. month(yy, mm) to print a specific month of a specific year.

Python Source Code

                                          import calendar  

yy = int(input("Enter year: "))  

mm = int(input("Enter month: "))  


Enter year: 2020
Enter month: 5
      May 2020
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