Python TextCalendar prmonth() Method with Example

Python TextCalendar.prmonth() Method: In this tutorial, we will learn about the prmonth() method of TextCalendar class in Python with its usage, syntax, and examples. By Hritika Rajput Last updated : April 24, 2023

Python TextCalendar.prmonth() Method

The TextCalendar.prmonth() method is an inbuilt method of the TextCalendar class of calendar module, it is used print the month of the given year. Also, there is no need for writing a print operation.

Module

The following module is required to use prmonth() method:

import calendar

Class

The following class is required to use prmonth() method:

from calendar import TextCalendar

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 specifies the year of the calendar.
  • month: It is a required parameter, which specifies the month of the calendar.
  • w: It is an optional parameter, which specifies the width of the date column; default value = 0.
  • l: It is an optional parameter, which represents the number of lines one week would use in the resulting string, default value = 0.

Return Value

The return type of this method is <class 'NoneType'>, it prints the corresponding calendar of the given year's month.

Example of TextCalendar.prmonth() Method in Python

# Python program to illustrate the 
# use of prmonth() method

# import class
import calendar

# creating a TextCalendar instance
cal = calendar.TextCalendar()
year = 2019
month = 12
print("Printing December 2019 calendar with default paramters, w = 0, l = 0")
cal.prmonth(year, month)
print()

# Setting width=3 
cal = calendar.TextCalendar()
year = 1919
month = 1
print("Printing January 1919 calendar with w = 3")
cal.prmonth(year, month, 3)
print()

# Setting width=5 length of one line=2 
cal = calendar.TextCalendar()
year = 1999
month = 11
print("Printing November 1999 calendar with w = 3, l = 2")
cal.prmonth(year, month, 3, 2)
print()

# Changing the firstweekday
cal = calendar.TextCalendar(firstweekday = 4)
# First column will be Friday
year = 2005
month = 5
print("Printing May 2005 calendar with  w = 3, l = 1 and first column starting with Friday")
cal.prmonth(year, month, 3, 1)
print()

Return Value

Printing December 2019 calendar with default paramters, w = 0, l = 0
   December 2019
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 31

Printing January 1919 calendar with w = 3
        January 1919
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  31

Printing November 1999 calendar with w = 3, l = 2
       November 1999

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 May 2005 calendar with  w = 3, l = 1 and first column starting with Friday
          May 2005
Fri Sat Sun Mon Tue Wed Thu
          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  31



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.