Python日历模块:iterweekdays() 方法
日历模块允许像程序一样输出日历,并提供与日历相关的附加有用功能。 Calendar 模块中定义的函数和类使用理想化的日历,当前的公历在两个方向上无限扩展。
iterweekdays()方法返回一个迭代器,用于表示将使用一周的工作日数。迭代器的第一个数字将与 firstweekday() 返回的数字相同。
Syntax: iterweekdays()
Parameter: no parameter
Returns: iterator for the week day numbers
代码#1:
# Python program to demonstrate working
# of iterweekdays() method
# importing calendar module
import calendar
# providing firstweekday = 0
obj = calendar.Calendar(firstweekday = 0)
for day in obj.iterweekdays():
print(day)
输出:
0
1
2
3
4
5
6
代码#2:
# Python program to demonstrate working
# of iterweekdays() method
# importing calendar module
import calendar
# providing firstweekday = 2
obj = calendar.Calendar(firstweekday = 2)
for day in obj.iterweekdays():
print(day)
输出:
2
3
4
5
6
0
1