当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。