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日歷模塊