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 example accepts year and month as input variables. And by using those values, we will display the monthly calendar.

import calendar

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

print(calendar.month(year, month))
Python Calendar Example

Within this example program, First, we import 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 numbers 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 example code displays 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 calendar library. This Python function accepts two parameters (i.e., Year and Month).