Home »
Python »
Python Reference »
Python calendar Module
Python calendar prmonth() Method with Example
Python calendar.prmonth() Method: In this tutorial, we will learn about the prmonth() method of calendar module in Python with its usage, syntax, and examples.
By Hritika Rajput Last updated : April 24, 2023
Python calendar.prmonth() Method
The calendar.prmonth() method is an inbuilt method of the calendar module, it is used to print the calendar of the given month of the given year. Also, there is no need of a print operation to execute this.
Module
The following module is required to use prmonth() method:
import calendar
Syntax
The following is the syntax of prmonth() method:
prmonth(year, month, w=0, l=0)
Parameter(s)
The following are the parameter(s):
- year: It is a required parameter, which represents the year of the calendar
- month: It is a required parameter, which represents the month of the calendar
- w: It is an optional parameter, which specifies the width of the date columns, which are centered.
- l: It is an optional argument, which represents the number of lines each week in the calendar will use.
Return Value
The return type of this method is <class 'NoneType'>, it does not return any value; it only prints the calendar of the given year's month.
Example of calendar.prmonth() Method in Python
# Python program to illustrate the
# use of prmonth() method
# importing calendar module
import calendar
# Printing April 2020 with column width=0
# and number of lines for each week=0
print("Printing calendar of April 2020 with default parameters")
calendar.prmonth(2020, 4)
print()
print("Printing April 2020 with column width=3")
calendar.prmonth(2020, 4, 3)
print()
print("Printing April 2020 with column width=5 and number of lines for each week=2")
calendar.prmonth(2020, 4, 5, 2)
print()
calendar.setfirstweekday(2)
# First column on the left will be Wednesday
print("Printing calendar of April 2020 with first column as Wednesday")
calendar.prmonth(2020, 4, 5, 1)
Output
Printing calendar of April 2020 with default parameters
April 2020
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
Printing April 2020 with column width=3
Printing calendar of April 2020 with default parameters
April 2020
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
Printing April 2020 with column width=3
April 2020
Mon Tue Wed Thu Fri Sat Sun
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
Printing April 2020 with column width=5 and number of lines for each week=2
April 2020
Mon Tue Wed Thu Fri Sat Sun
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
Printing calendar of April 2020 with first column as Wednesday
April 2020
Wed Thu Fri Sat Sun Mon Tue
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