當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Python calendar firstweekday()用法及代碼示例


Python calendar.firstweekday() 方法

firstweekday() 方法是 Python 中日曆模塊的內置方法。它適用於簡單的文本日曆,並返回每周開始的工作日的當前設置。

模塊:

    import calendar

用法:

    firstweekday()

參數:

  • None

返回值:

該函數返回一個從 0 到 6 的數字,其中星期一表示 0,依此類推。

例:

# Python program to illustrate the 
# use of firstweekday() method
  
# importing calendar module 
import calendar 
  
# using setfirstweekday() function 
calendar.setfirstweekday(2) 
print(calendar.firstweekday())
print()

val = calendar.setfirstweekday(calendar.FRIDAY)
# sets the value to 4 which is the weekday value for FRIDAY
print(calendar.firstweekday())
# prints 4
print()

# Printing 3rd month of 2020
calendar.setfirstweekday(calendar.THURSDAY)
print("Third month of 2020:")
calendar.prmonth(2020, 3, 2, 1)
# It starts displaying the calendar from THURSDAY
print("The first weekday of the third month of 2020 is:", calendar.firstweekday())

輸出

2

4

Third month of 2020:
     March 2020
Th Fr Sa Su Mo Tu We
          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 31
The first weekday of the third month of 2020 i
s:3


相關用法


注:本文由純淨天空篩選整理自 Python calendar Module | firstweekday() Method with Example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。