English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Python basic tutorial

Python flow control

Python Functions

Python Data Types

Python file operations

Python objects and classes

Python date and time

Advanced knowledge of Python

Python reference manual

Python program to display calendar

Python instance manual

Python has built-in functions, the calendar module can handle date-related tasks. In this example, you will learn to display the calendar for a given date.

To understand this example, you should understand the followingPython programmingTopic:

In the following program, we import the calendar module. The built-in function month() within the module accepts the year and month and displays the calendar for that month.

Source code

# Program to display calendar for a given month and year
# Import calendar module
import calendar
yy = 2014  # year
mm = 11    # month
# Get user's month and year input
# yy = int(input("Enter year: "))
# mm = int(input("Enter month: "))
# Display calendar
print(calendar.month(yy, mm))

Output result

   November 2014
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

You can change the values of variables yy and mm, and then run it to test this program for other dates.

Python instance manual