日曆模塊允許輸出類似於程序的日曆,並提供與日曆相關的其他有用函數。 “日曆”模塊中定義的函數和類使用理想化的日曆,當前的公曆日曆在兩個方向上都無限期擴展。
在Python中,calendar.firstweekday()是日曆模塊中提供的用於簡單文本日曆的函數。
firstweekday()方法用於獲取每周開始的工作日的當前設置。
用法: firstweekday() 參數: no parameter 返回: None
代碼1:
# Python program to explain working of firstweekday() method
# importing calendar module
import calendar
# default firstweekday
print("Default First weekday is - ", calendar.firstweekday())
# setting 2nd day as firstweekday
calendar.setfirstweekday(2)
# print firstweekday
print("First weekday after modification is - ", calendar.firstweekday())
輸出:
Default First weekday is - 6 First weekday after modification is - 2
代碼2:用prmonth()方法解釋firstweekday()方法的用法
# Python code to demonstrate the working of
# firstweekday() with help of prmonth() method
# importing calendar module for calendar operations
import calendar
# using prmonth() to print calendar of 1997
print ("The 4th month of 1997 is:")
calendar.prmonth(1997, 4, 2, 1)
# using setfirstweekday() to set first week day number
calendar.setfirstweekday(4)
print("First weekday after modification is - ",
calendar.firstweekday())
輸出:
The 4th month of 1997 is: April 1997 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 First weekday after modification is - 4
相關用法
- Python calendar isleap()用法及代碼示例
- Python calendar setfirstweekday()用法及代碼示例
- Python calendar itermonthdays()用法及代碼示例
- Python calendar iterweekdays()用法及代碼示例
- Python calendar itermonthdays2()用法及代碼示例
- Python calendar monthdatescalendar()用法及代碼示例
- Python calendar yeardayscalendar()用法及代碼示例
- Python calendar leapdays()用法及代碼示例
- Python calendar yeardays2calendar()用法及代碼示例
- Python calendar yeardatescalendar()用法及代碼示例
- Python calendar monthdayscalendar()用法及代碼示例
- Python calendar monthdays2calendar()用法及代碼示例
- Python calendar pryear()用法及代碼示例
- Python calendar prmonth()用法及代碼示例
- Python calendar formatyear()用法及代碼示例
注:本文由純淨天空篩選整理自Shivam_k大神的英文原創作品 Python calendar module | firstweekday() method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。