python 示例
Python TextCalendar.pryear()方法 (Python TextCalendar.pryear() Method)
pryear() 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 calendar for an entire year Also, there is no need for a "print" operation to execute this.
pryear()方法是Python中日历模块的TextCalendar类的内置方法。 它适用于文本日历。 它使用TextCalendar类的实例并打印整年的日历。此外,不需要执行“打印”操作即可执行此操作。
Module:
模块:
import calendar
Class:
类:
from calendar import TextCalendar
Syntax:
句法:
pryear(year, w=2, l=1, c=6, m=3)
Parameter(s):
参数:
year: It is a required parameter, which specifies the year of the calendar.
year :这是必填参数,用于指定日历的年份。
w: It is an optional parameter, which specifies the width of the date column; default value = 2.
w :这是一个可选参数,用于指定日期列的宽度; 默认值= 2。
l: It is an optional parameter, which represents the number of lines one week would use in the resulting string; default value = 1.
l :这是一个可选参数,代表一周中将在结果字符串中使用的行数; 默认值= 1。
c: It is an optional parameter, which specifies the number of spaces between month columns; default value = 6.
c :这是一个可选参数,用于指定月份列之间的空格数; 默认值= 6
m: It is an optional parameter, which represents the number of column of months in a row in the calendar; default value = 3.
m :这是一个可选参数,代表日历中一行中月份的列数; 默认值= 3。
Return value:
返回值:
The return type of this method is <class 'NoneType'>, it prints an m-column calendar for an entire year.
此方法的返回类型为<class'NoneType'> ,它将打印整个一年的m列日历。
Example:
例:
# Python program to illustrate the
# use of pryear() method
# import class
import calendar
# creating a TextCalendar instance
cal = calendar.TextCalendar()
year = 2019
print("2019 calendar with default values w=2, l=1, c=6, m=3")
cal.pryear(year)
print()
# Setting c =3, l=2,w=3
cal = calendar.TextCalendar()
year = 1919
print("1919 calendar with w=3, l=2, c=3")
# Parameters missing have default values
cal.pryear(year, 3, 2, 3)
print()
# Setting m=2
# Number of months in a row will be 2
cal = calendar.TextCalendar()
year = 1999
print("1999 calendar with number of month columns in a row=2")
cal.pryear(year, m=2)
print()
Output
输出量
2019 calendar with default values w=2, l=1, c=6, m=3
2019
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
1919 calendar with w=3, l=2, c=3
1919
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 4 5 1 2 1 2
6 7 8 9 10 11 12 3 4 5 6 7 8 9 3 4 5 6 7 8 9
13 14 15 16 17 18 19 10 11 12 13 14 15 16 10 11 12 13 14 15 16
20 21 22 23 24 25 26 17 18 19 20 21 22 23 17 18 19 20 21 22 23
27 28 29 30 31 24 25 26 27 28 24 25 26 27 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 4 5 6 1 2 3 4 1
7 8 9 10 11 12 13 5 6 7 8 9 10 11 2 3 4 5 6 7 8
14 15 16 17 18 19 20 12 13 14 15 16 17 18 9 10 11 12 13 14 15
21 22 23 24 25 26 27 19 20 21 22 23 24 25 16 17 18 19 20 21 22
28 29 30 26 27 28 29 30 31 23 24 25 26 27 28 29
30
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 4 5 6 1 2 3 1 2 3 4 5 6 7
7 8 9 10 11 12 13 4 5 6 7 8 9 10 8 9 10 11 12 13 14
14 15 16 17 18 19 20 11 12 13 14 15 16 17 15 16 17 18 19 20 21
21 22 23 24 25 26 27 18 19 20 21 22 23 24 22 23 24 25 26 27 28
28 29 30 31 25 26 27 28 29 30 31 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 3 4 5 1 2 1 2 3 4 5 6 7
6 7 8 9 10 11 12 3 4 5 6 7 8 9 8 9 10 11 12 13 14
13 14 15 16 17 18 19 10 11 12 13 14 15 16 15 16 17 18 19 20 21
20 21 22 23 24 25 26 17 18 19 20 21 22 23 22 23 24 25 26 27 28
27 28 29 30 31 24 25 26 27 28 29 30 29 30 31
1999 calendar with number of month columns in a row=2
1999
January February
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
1 2 3 1 2 3 4 5 6 7
4 5 6 7 8 9 10 8 9 10 11 12 13 14
11 12 13 14 15 16 17 15 16 17 18 19 20 21
18 19 20 21 22 23 24 22 23 24 25 26 27 28
25 26 27 28 29 30 31
March April
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
8 9 10 11 12 13 14 5 6 7 8 9 10 11
15 16 17 18 19 20 21 12 13 14 15 16 17 18
22 23 24 25 26 27 28 19 20 21 22 23 24 25
29 30 31 26 27 28 29 30
May June
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
1 2 1 2 3 4 5 6
3 4 5 6 7 8 9 7 8 9 10 11 12 13
10 11 12 13 14 15 16 14 15 16 17 18 19 20
17 18 19 20 21 22 23 21 22 23 24 25 26 27
24 25 26 27 28 29 30 28 29 30
31
July August
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
1 2 3 4 1
5 6 7 8 9 10 11 2 3 4 5 6 7 8
12 13 14 15 16 17 18 9 10 11 12 13 14 15
19 20 21 22 23 24 25 16 17 18 19 20 21 22
26 27 28 29 30 31 23 24 25 26 27 28 29
30 31
September October
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
1 2 3 4 5 1 2 3
6 7 8 9 10 11 12 4 5 6 7 8 9 10
13 14 15 16 17 18 19 11 12 13 14 15 16 17
20 21 22 23 24 25 26 18 19 20 21 22 23 24
27 28 29 30 25 26 27 28 29 30 31
November December
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
8 9 10 11 12 13 14 6 7 8 9 10 11 12
15 16 17 18 19 20 21 13 14 15 16 17 18 19
22 23 24 25 26 27 28 20 21 22 23 24 25 26
29 30 27 28 29 30 31
翻译自: https://www.includehelp.com/python/textcalendar-pryear-method-with-example.aspx
python 示例