python日历模块
Python calendar.prmonth()方法 (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.
prmonth()方法是Python中日历模块的内置方法。 它适用于简单的文本日历,并打印给定年份中给定月份的日历。 同样,也不需要执行“打印”操作。
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
year :这是必填参数,代表日历的年份
month: It is a required parameter, which represents the month of the calendar
month :这是必填参数,代表日历的月份
w: It is an optional parameter, which specifies the width of the date columns, which are centered.
w :这是一个可选参数,用于指定日期列的宽度(居中)。
l: It is an optional argument, which represents the number of lines each week in the calendar will use.
l :这是一个可选参数,代表日历中每周将使用的行数。
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.
此方法的返回类型为<class'NoneType'> ,它不返回任何值; 它仅打印给定年份月份的日历。
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
翻译自: https://www.includehelp.com/python/calendar-prmonth-method-with-example.aspx
python日历模块