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


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


Python calendar.weekheader() 方法

weekheader() 方法是 Python 中日曆模塊的內置方法。它適用於簡單的文本日曆並返回一個包含工作日縮寫名稱的標題。

模塊:

    import calendar

用法:

    weekheader(n)

參數:

  • n: 必填參數,表示一個工作日的寬度(以字符為單位)。

返回值:

這個方法的返回類型是<class 'str'>(一個字符串),它返回一個包含縮寫工作日名稱的標題。

例:

## Python program to illustrate the 
## use of weekheader() method
  
# importing calendar module 
import calendar 

n = 1
print("When width in character for one weekday = 1")
print(calendar.weekheader(n))
print()

n = 3
print("When width in character for one weekday = 3")
print(calendar.weekheader(n))
print()

n = 5
print("When width in character for one weekday = 5")
print(calendar.weekheader(n))
print()

n = 10
print("When width in character for one weekday = 10")
print(calendar.weekheader(n))
print()

n = 15
print("When width in character for one weekday = 15")
print(calendar.weekheader(n))

輸出

When width in character for one weekday = 1
M T W T F S S

When width in character for one weekday = 3
Mon Tue Wed Thu Fri Sat Sun

When width in character for one weekday = 5
 Mon   Tue   Wed   Thu   Fri   Sat   Sun 

When width in character for one weekday = 10
  Monday    Tuesday   Wednesday   Thursday    Friday    Saturday    
  Sunday  

When width in character for one weekday = 15
     Monday         Tuesday        Wednesday        Thursday         
     Friday         Saturday         Sunday 


相關用法


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