w3resource

Python TextCalendar: formatyear() method

formatyear() method

The formatyear() method is used to get a m-column calendar for an entire year as a multi-line string.

Syntax:

formatyear(theyear, w=2, l=1, c=6, m=3)

Parameters:

Name Description Required /
Optional
Type
year Year for which the calendar should be generated. Required Number
w The width between two columns. Default value is 2. Optional Number
l Blank line between two rows. Default value is 1. Optional Number
c Space between two months (Column wise). Default value is 6. Optional Number
m Number of months in a row. Default value is 3. Optional Number

Depends on the first weekday as specified in the constructor or set by the setfirstweekday() method.
The earliest year for which a calendar can be generated is platform-dependent.

Example of Text-calendar-formatmonth() method

import calendar
tc= calendar.TextCalendar(firstweekday=0)
print(tc.formatyear(2016, 5))

Output:

2016

                 January                                       February                                         March
 Mon   Tue   Wed   Thu   Fri   Sat   Sun        Mon   Tue   Wed   Thu   Fri   Sat   Sun        Mon   Tue   Wed   Thu   Fri   Sat   Sun
                          1     2     3          1     2     3     4     5     6     7                1     2     3     4     5     6
  4     5     6     7     8     9    10          8     9    10    11    12    13    14          7     8     9    10    11    12    13
 11    12    13    14    15    16    17         15    16    17    18    19    20    21         14    15    16    17    18    19    20
 18    19    20    21    22    23    24         22    23    24    25    26    27    28         21    22    23    24    25    26    27
 25    26    27    28    29    30    31         29                                             28    29    30    31

                  April                                           May                                           June
 Mon   Tue   Wed   Thu   Fri   Sat   Sun        Mon   Tue   Wed   Thu   Fri   Sat   Sun        Mon   Tue   Wed   Thu   Fri   Sat   Sun
                          1     2     3                                              1                      1     2     3     4     5
  4     5     6     7     8     9    10          2     3     4     5     6     7     8          6     7     8     9    10    11    12
 11    12    13    14    15    16    17          9    10    11    12    13    14    15         13    14    15    16    17    18    19
 18    19    20    21    22    23    24         16    17    18    19    20    21    22         20    21    22    23    24    25    26
 25    26    27    28    29    30               23    24    25    26    27    28    29         27    28    29    30
                                                30    31

                  July                                          August                                        September
 Mon   Tue   Wed   Thu   Fri   Sat   Sun        Mon   Tue   Wed   Thu   Fri   Sat   Sun        Mon   Tue   Wed   Thu   Fri   Sat   Sun
                          1     2     3          1     2     3     4     5     6     7                            1     2     3     4
  4     5     6     7     8     9    10          8     9    10    11    12    13    14          5     6     7     8     9    10    11
 11    12    13    14    15    16    17         15    16    17    18    19    20    21         12    13    14    15    16    17    18
 18    19    20    21    22    23    24         22    23    24    25    26    27    28         19    20    21    22    23    24    25
 25    26    27    28    29    30    31         29    30    31                                 26    27    28    29    30

                 October                                       November                                       December
 Mon   Tue   Wed   Thu   Fri   Sat   Sun        Mon   Tue   Wed   Thu   Fri   Sat   Sun        Mon   Tue   Wed   Thu   Fri   Sat   Sun
                                1     2                1     2     3     4     5     6                            1     2     3     4
  3     4     5     6     7     8     9          7     8     9    10    11    12    13          5     6     7     8     9    10    11
 10    11    12    13    14    15    16         14    15    16    17    18    19    20         12    13    14    15    16    17    18
 17    18    19    20    21    22    23         21    22    23    24    25    26    27         19    20    21    22    23    24    25
 24    25    26    27    28    29    30         28    29    30                                 26    27    28    29    30    31
 31

Previous: prmonth()
Next: pryear()

Test your Python skills with w3resource's quiz



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/python/module/calendar/text-calendar-formatyear.php