Python日历类| 带示例的iterweekdays()方法

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

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值