Python calendar.prmonth() 方法
prmonth() 方法是 Python 中日曆模塊的內置方法。它適用於簡單的文本日曆並打印給定年份的給定月份的日曆。此外,不需要 "print" 操作來執行此操作。
模塊:
import calendar
用法:
prmonth(year, month, w=0, l=0)
參數:
year
: 必選參數,代表日曆的年份month
: 必選參數,代表日曆的月份w
:它是一個可選參數,它指定居中的日期列的寬度。l
:它是一個可選參數,表示日曆中每周將使用的行數。
返回值:
這個方法的返回類型是<class 'NoneType'>
,它不返回任何值;它隻打印給定年份月份的日曆。
例:
# 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)
輸出
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
相關用法
- Python calendar prcal()用法及代碼示例
- Python calendar firstweekday()用法及代碼示例
- Python calendar weekday()用法及代碼示例
- Python calendar isleap()用法及代碼示例
- Python calendar setfirstweekday()用法及代碼示例
- Python calendar leapdays()用法及代碼示例
- Python calendar weekheader()用法及代碼示例
- Python calendar calendar()用法及代碼示例
- Python calendar monthcalendar()用法及代碼示例
- Python calendar month()用法及代碼示例
- Python calendar monthrange()用法及代碼示例
- Python callable()用法及代碼示例
- Python string capwords()用法及代碼示例
- Python Functools cached_property()用法及代碼示例
- Python cmath.isclose()用法及代碼示例
- Python cmp()用法及代碼示例
- Python compile()用法及代碼示例
- Python cmath.log10()用法及代碼示例
- Python cmath.asinh()用法及代碼示例
- Python OpenCV cv2.rectangle()用法及代碼示例
注:本文由純淨天空篩選整理自 Python calendar Module | prmonth() Method with Example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。