Python program to print calendar
Python program to print the calendar
This article will explain how to print the calendar of month and year using Python's calendar module. It's a straightforward thing in Python by importing a module calendar in the program. This module provides an inbuilt function month() that takes year and month as a parameter and displays the calendar.
Source Code
The following source code will print the particular month calendar of the specified year:
#Program to display the calendar import calendar year = int(input("Enter year: ")) month = int(input("Enter month: ")) # display the calendar print(calendar.month(year, month))
Output
Here is the result:

Explanation: In this program, we need to import the module calendar. A user will be asked to enter year and month as input, and this input will be stored in a separate variable. These inputs will be passed to the calendar.month() to print the result. Finally, the result will be printed.
The following source code prints the calendar of the given year. Here we first import the calendar module, then initialize the year number, and finally print the calendar using the calendar.calendar(year) class.
#import calendar module import calendar #initialize the year year = 2020 #display the calendar print(calendar.calendar(year))
Output
Here is the output:
