Calendar Module:
The calendar module allows you to output calendars like a program and includes extra calendar-related operations. Calendar module functions and classes make use of an idealized calendar, the current Gregorian calendar extended in both directions indefinitely.
iterweekdays() method:
The iterweekdays() method returns an iterator of weekday numbers for one week. The first number returned by the iterator will be the same as the firstweekday() returned number.
Syntax:
iterweekdays()
Parameters: This method has no parameters.
Return Value: Returns an iterator of weekday numbers.
Program for calendar iterweekdays() Method with Examples in Python
Method #1: Using Built-in Functions (Static Input)
Example1:
Approach:
- Import calendar module using the import keyword.
- Set the firstweekday=0 using the Calendar() function by passing the firstweekday=0 as an argument.
- Store it in a variable.
- Apply the iterweekdays() method for the above result and store it in another variable.
- Iterate in the above result using the for loop.
- Inside the loop, print the iterator value.
- The Exit of the Program.
Below is the implementation:
# Import calendar module using the import keyword. import calendar # Set the firstweekday=0 using the Calendar() function by passing the # firstweekday=0 as an argument. # Store it in a variable. calendr = calendar.Calendar(firstweekday=0) # Apply the iterweekdays() method for the above result and store it in # another variable. rslt = calendr.iterweekdays() # Iterate in the above result using the for loop. for itr in rslt: # Inside the loop, print the iterator value. print(itr)
Output:
0 1 2 3 4 5 6
Explanation:
It prints the seven days of the week starting from 0
Example2:
Approach:
- Import calendar module using the import keyword.
- Set the firstweekday=2 using the Calendar() function by passing the firstweekday=2 as an argument.
- Store it in a variable.
- Apply the iterweekdays() method for the above result and store it in another variable.
- Iterate in the above result using the for loop.
- Inside the loop, print the iterator value.
- The Exit of the Program.
Below is the implementation:
# Import calendar module using the import keyword. import calendar # Set the firstweekday=2 using the Calendar() function by passing the # firstweekday=2 as an argument. # Store it in a variable. calendr = calendar.Calendar(firstweekday=2) # Apply the iterweekdays() method for the above result and store it in # another variable. rslt = calendr.iterweekdays() # Iterate in the above result using the for loop. for itr in rslt: # Inside the loop, print the iterator value. print(itr)
Output:
2 3 4 5 6 0 1
Explanation:
It prints the seven days of the week starting from 2