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


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。