Python Calendar Example

In this section, we show how to write a Python program to display the monthly calendar with an example.

Python Calendar Example

This Python calendar example accepts year and month as input variables. And by using those values, we are going to display the monthly calendar.

# Python Calendar Example

# import calendar module
import calendar

# ask of month and year
year = int(input("Please Enter the year Number: "))
month = int(input("Please Enter the month Number: "))

# Displaying the Python calendar
print(calendar.month(year, month))
Python Calendar Example

Within this Python calendar example program, First, we are importing the calendar library provided by the Python programming language. The group of functions present in this library can help you to perform many operations on the calendar.

import calendar

Next, we are asking the users to enter the Year and Month number using the following statements. To make sure that they are entering the integer values, we used the typecast here.

year = int(input("Please Enter the year Number: "))
month = int(input("Please Enter the month Number: "))

The following statement in the calendar example program display the monthly calendar (Here, February 2016).

print(calendar.month(year, month))

From the above statement, you can observe that we were calling the month function present in the python calendar library. This Python function accepts two parameters (i.e., Year and Month).