Thursday, September 4, 2025
HomeLanguagesCalendar in Python

Calendar in Python

Python has a built-in Python Calendar module to work with date-related tasks. Using the module, we can display a particular month as well as the whole calendar of a year. In this article, we will see how to print a calendar month and year using Python.

Calendar in Python Example

Input:
yy = 2023
mm = 4

Output:

Calendar in Python

Calendar of April 2023

Displaying a Calendar for a Month in Python

In the program below, we import the Python calendar module. The built-in function month() inside the module takes in the year and the month and displays the calendar for that month of the year.

Python3




# import module
import calendar
 
yy = 2023
mm = 4
 
# display the calendar
print(calendar.month(yy, mm))


Output:

Displaying a Calendar for a Month in Python

Calendar of April 2023

OR, you can directly run from the command line (CMD in Windows or TERMINAL in Linux ) for displaying a month of a year. Just write the following command:

python -m calendar 2023 4

Output:

Calendar of April 2023

Calendar of April 2023

Displaying Calendar of a given Year in Python

In the program below, we import the calendar module. The built-in Python calendar() function inside the module takes in the year and displays the calendar for that year.

Python3




# import module
import calendar
 
yy = 2017
 
# display the calendar
print(calendar.calendar(yy))


Output:

Displaying Calendar of a given Year in Python

Calendar of 2023

OR, you can directly run from the command line (CMD in Windows or TERMINAL in Linux ) for displaying a year:

python -m calendar 2023

Output:

Calendar of 2023

Calendar of 2023

RELATED ARTICLES

Most Popular

Dominic
32261 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6626 POSTS0 COMMENTS
Nicole Veronica
11795 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11855 POSTS0 COMMENTS
Shaida Kate Naidoo
6747 POSTS0 COMMENTS
Ted Musemwa
7023 POSTS0 COMMENTS
Thapelo Manthata
6695 POSTS0 COMMENTS
Umr Jansen
6714 POSTS0 COMMENTS