Python calendar calendar() Method with Example

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

Python calendar.calendar() Method

The calendar.calendar() method is an inbuilt method of the calendar module in Python which works on simple text calendars and it returns a 3-column calendar for an entire year as a multi-line string.

Module

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

import calendar

Syntax

The following is the syntax of calendar() method:

calendar(year, w=0, l=0, c=6, m=3)

Parameter(s)

The following are the parameter(s):

  • year: value of the year
  • w: date column width
  • l: lines per week
  • c: number of spaces between month columns
  • m: number of column of months in a row,

Return Value

The function returns a month's calendar in a multi-line string.

Example of calendar.calendar() Method in Python

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

# importing calendar module
import calendar

# Printing 2020 calendar using default parameters
print(calendar.calendar(2020))
print()

# printing 1991 calendar with w=2, l=2
print(calendar.calendar(1991, 2, 2))
print()

# printing 1930 calendar with w=1,l=1,c=2
print(calendar.calendar(2020, 1, 1, 2))

Output

      January                   February                   March
Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su
       1  2  3  4  5                      1  2                         1
 6  7  8  9 10 11 12       3  4  5  6  7  8  9       2  3  4  5  6  7  8
13 14 15 16 17 18 19      10 11 12 13 14 15 16       9 10 11 12 13 14 15
20 21 22 23 24 25 26      17 18 19 20 21 22 23      16 17 18 19 20 21 22
27 28 29 30 31            24 25 26 27 28 29         23 24 25 26 27 28 29
                                                    30 31

       April                      May                       June
Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su
       1  2  3  4  5                   1  2  3       1  2  3  4  5  6  7
 6  7  8  9 10 11 12       4  5  6  7  8  9 10       8  9 10 11 12 13 14
13 14 15 16 17 18 19      11 12 13 14 15 16 17      15 16 17 18 19 20 21
20 21 22 23 24 25 26      18 19 20 21 22 23 24      22 23 24 25 26 27 28
27 28 29 30               25 26 27 28 29 30 31      29 30

        July                     August                  September
Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su
       1  2  3  4  5                      1  2          1  2  3  4  5  6
 6  7  8  9 10 11 12       3  4  5  6  7  8  9       7  8  9 10 11 12 13
13 14 15 16 17 18 19      10 11 12 13 14 15 16      14 15 16 17 18 19 20
20 21 22 23 24 25 26      17 18 19 20 21 22 23      21 22 23 24 25 26 27
27 28 29 30 31            24 25 26 27 28 29 30      28 29 30
                          31

      October                   November                  December
Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su
          1  2  3  4                         1          1  2  3  4  5  6
 5  6  7  8  9 10 11       2  3  4  5  6  7  8       7  8  9 10 11 12 13
12 13 14 15 16 17 18       9 10 11 12 13 14 15      14 15 16 17 18 19 20
19 20 21 22 23 24 25      16 17 18 19 20 21 22      21 22 23 24 25 26 27
26 27 28 29 30 31         23 24 25 26 27 28 29      28 29 30 31
                          30


                                  1991



      January                   February                   March

Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su

    1  2  3  4  5  6                   1  2  3                   1  2  3

 7  8  9 10 11 12 13       4  5  6  7  8  9 10       4  5  6  7  8  9 10

14 15 16 17 18 19 20      11 12 13 14 15 16 17      11 12 13 14 15 16 17

21 22 23 24 25 26 27      18 19 20 21 22 23 24      18 19 20 21 22 23 24

28 29 30 31               25 26 27 28               25 26 27 28 29 30 31



       April                      May                       June

Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su

 1  2  3  4  5  6  7             1  2  3  4  5                      1  2

 8  9 10 11 12 13 14       6  7  8  9 10 11 12       3  4  5  6  7  8  9

15 16 17 18 19 20 21      13 14 15 16 17 18 19      10 11 12 13 14 15 16

22 23 24 25 26 27 28      20 21 22 23 24 25 26      17 18 19 20 21 22 23

29 30                     27 28 29 30 31            24 25 26 27 28 29 30



        July                     August                  September

Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su

 1  2  3  4  5  6  7                1  2  3  4                         1

 8  9 10 11 12 13 14       5  6  7  8  9 10 11       2  3  4  5  6  7  8

15 16 17 18 19 20 21      12 13 14 15 16 17 18       9 10 11 12 13 14 15

22 23 24 25 26 27 28      19 20 21 22 23 24 25      16 17 18 19 20 21 22

29 30 31                  26 27 28 29 30 31         23 24 25 26 27 28 29

                                                    30



      October                   November                  December

Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su

    1  2  3  4  5  6                   1  2  3                         1

 7  8  9 10 11 12 13       4  5  6  7  8  9 10       2  3  4  5  6  7  8

14 15 16 17 18 19 20      11 12 13 14 15 16 17       9 10 11 12 13 14 15

21 22 23 24 25 26 27      18 19 20 21 22 23 24      16 17 18 19 20 21 22

28 29 30 31               25 26 27 28 29 30         23 24 25 26 27 28 29

                                                    30 31



                              2020

      January               February               March
Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su
       1  2  3  4  5                  1  2                     1
 6  7  8  9 10 11 12   3  4  5  6  7  8  9   2  3  4  5  6  7  8
13 14 15 16 17 18 19  10 11 12 13 14 15 16   9 10 11 12 13 14 15
20 21 22 23 24 25 26  17 18 19 20 21 22 23  16 17 18 19 20 21 22
27 28 29 30 31        24 25 26 27 28 29     23 24 25 26 27 28 29
                                            30 31

       April                  May                   June
Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su
       1  2  3  4  5               1  2  3   1  2  3  4  5  6  7
 6  7  8  9 10 11 12   4  5  6  7  8  9 10   8  9 10 11 12 13 14
13 14 15 16 17 18 19  11 12 13 14 15 16 17  15 16 17 18 19 20 21
20 21 22 23 24 25 26  18 19 20 21 22 23 24  22 23 24 25 26 27 28
27 28 29 30           25 26 27 28 29 30 31  29 30

        July                 August              September
Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su
       1  2  3  4  5                  1  2      1  2  3  4  5  6
 6  7  8  9 10 11 12   3  4  5  6  7  8  9   7  8  9 10 11 12 13
13 14 15 16 17 18 19  10 11 12 13 14 15 16  14 15 16 17 18 19 20
20 21 22 23 24 25 26  17 18 19 20 21 22 23  21 22 23 24 25 26 27
27 28 29 30 31        24 25 26 27 28 29 30  28 29 30
                      31

      October               November              December
Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su
          1  2  3  4                     1      1  2  3  4  5  6
 5  6  7  8  9 10 11   2  3  4  5  6  7  8   7  8  9 10 11 12 13
12 13 14 15 16 17 18   9 10 11 12 13 14 15  14 15 16 17 18 19 20
19 20 21 22 23 24 25  16 17 18 19 20 21 22  21 22 23 24 25 26 27
26 27 28 29 30 31     23 24 25 26 27 28 29  28 29 30 31
                      30



Comments and Discussions!

Load comments ↻





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