Python TextCalendar Class | prmonth() Method with Example

Python TextCalendar.prmonth() Method: Here, we are going to learn about the prmonth() method of TextCalendar class in Python with its definition, syntax, and examples.
Submitted by Hritika Rajput, on May 09, 2020

Python TextCalendar.prmonth() Method

prmonth() method is an inbuilt method of the TextCalendar class of calendar module in Python. It works on text calendars. It uses an instance of TextCalendar class and prints the month of the given year. Also, there is no need for writing "print" operation.

Module:

    import calendar

Class:

    from calendar import TextCalendar

Syntax:

    prmonth(year, month, w=0, l=0)

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:

# 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()

Output

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




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.