w3resource

Python Calendar Module: iterweekdays() method

iterweekdays() method

The iterweekdays() method returns an iterator for the weekday numbers that will be used for one week. The first number from the iterator will be the same as the number returned by firstweekday().

Syntax

iterweekdays()

Example -1: Python iterweekdays() method

import calendar
#set firstweekday=0
cal= calendar.Calendar(firstweekday=0)
for x in cal.iterweekdays():
	print(x)

Output:

0
1
2
3
4
5
6

Example - 2: iterweekdays() method

import calendar
#set firstweekday=1
cal= calendar.Calendar(firstweekday=1)
for x in cal.iterweekdays():
print(x)

Output:

1
2
3
4
5
6
0

Note: firstweekday() - Return an array for one week of weekday numbers starting with the configured first one.

Previous: Home - Python Calendar Module
Next: itermonthdates()

Test your Python skills with w3resource's quiz



Python: Tips of the Day

What is the difference between Python's list methods append and extend?

append: Appends object at the end.

x = [1, 2, 3]
x.append([4, 5])
print (x)

Output:

[1, 2, 3, [4, 5]]

extend: Extends list by appending elements from the iterable.

x = [1, 2, 3]
x.extend([4, 5])
print (x)

Output:

[1, 2, 3, 4, 5]

Ref: https://bit.ly/2AZ6ZFq