Python Calendar.iterweekdays()方法 (Python Calendar.iterweekdays() Method)
Calendar.iterweekdays() method is an inbuilt method of the Calendar class of calendar module in Python. It uses an instance of this class and returns an iterator for the weekday numbers that are used for one week. The first number that the iterator returns is the first weekday set for that instance. By default, the first-weekday set is 0 which is Monday.
Calendar.iterweekdays()方法是Python中Calendar模块的Calendar类的内置方法。 它使用此类的实例,并为一个星期使用的星期几返回一个迭代器。 迭代器返回的第一个数字是该实例设置的第一个工作日。 默认情况下,第一个工作日设置为0,即星期一。
Module:
模块:
import calendar
Class:
类:
from calendar import Calendar
Syntax:
句法:
iterweekdays()
Parameter(s):
参数:
None
没有
Return value:
返回值:
The return type of this method is <class 'generator'>, it returns an iterator for the weekday numbers giving 7 weekday numbers starting from that iterator.
此方法的返回类型为<class'generator'> ,它返回工作日编号的迭代器,从该迭代器开始提供7个工作日编号。
Example:
例:
# 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()
Output
输出量
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
翻译自: https://www.includehelp.com/python/calendar-calendar-iterweekdays-method-with-example.aspx