Python Calendar.iterweekdays() 方法
Calendar.iterweekdays() 方法是內置的方法Calendar
類calendar
Python 中的模塊。它使用此類的一個實例,並返回一個用於一周的工作日數字的迭代器。迭代器返回的第一個數字是為該實例設置的第一個工作日。默認情況下,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 itermonthdays2()用法及代碼示例
- Python Calendar itermonthdates()用法及代碼示例
- Python Calendar itermonthdays3()用法及代碼示例
- Python Calendar itermonthdays4()用法及代碼示例
- Python Calendar itermonthdays()用法及代碼示例
- Python Calendar monthdatescalendar()用法及代碼示例
- Python Calendar monthdayscalendar()用法及代碼示例
- Python Calendar yeardatescalendar()用法及代碼示例
- Python Calendar yeardayscalendar()用法及代碼示例
- Python Calendar yeardays2calendar()用法及代碼示例
- Python Calendar monthdays2calendar()用法及代碼示例
- Python Condition release()用法及代碼示例
- Python Collections.UserString用法及代碼示例
- Python Condition notify()用法及代碼示例
- Python Condition wait()用法及代碼示例
- Python Sympy Curve.translate()用法及代碼示例
- Python Collections.UserDict用法及代碼示例
- Python Collections.UserList用法及代碼示例
- Python Condition notify_all()用法及代碼示例
- Python Condition acquire()用法及代碼示例
注:本文由純淨天空篩選整理自 Python Calendar Class | iterweekdays() Method with Example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。