ADVERTISEMENT
ADVERTISEMENT

Python calendar Module | prmonth() Method with Example

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

Python calendar.prmonth() Method

prmonth() method is an inbuilt method of the calendar module in Python. It works on simple text calendars and prints the calendar of the given month of the given year. Also, there is no need of "print" operation to execute this.

Module:

    import calendar

Syntax:

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

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:

# 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
ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

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.