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


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