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


Python Calendar iterweekdays()用法及代码示例


Python Calendar.iterweekdays() 方法

Calendar.iterweekdays() 方法是内置的方法CalendarcalendarPython 中的模块。它使用此类的一个实例,并返回一个用于一周的工作日数字的迭代器。迭代器返回的第一个数字是为该实例设置的第一个工作日。默认情况下,first-weekday 集为 0,即星期一。

模块:

    import calendar

类:

    from calendar import Calendar

用法:

    iterweekdays()

参数:

  • None

返回值:

这个方法的返回类型是<class 'generator'>,它返回工作日数字的迭代器,从该迭代器开始给出 7 个工作日数字。

例:

# Python program to illustrate the 
# use of iterweekdays() method

# import module
import calendar

# Creating Calendar instance
cal = calendar.Calendar()
print("Iterating with first weekday as 0, ie, Monday")
for i in cal.iterweekdays():
    print(i)
print()

# Changing firstweekday for the Calendar
cal  = calendar.Calendar(firstweekday = 3)
# iterator starts with 3
print("Iterating with first weekday as 3, ie, Thursday")
for i in cal.iterweekdays():
    print(i)
print()

输出

Iterating with first weekday as 0, ie, Monday
0
1
2
3
4
5
6

Iterating with first weekday as 3, ie, Thursday
3
4
5
6
0
1
2


相关用法


注:本文由纯净天空筛选整理自 Python Calendar Class | iterweekdays() Method with Example。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。