calendar.Calendar().iterweekdays() returns an iterator of seven weekday numbers in calendar display order. By default, Monday is first (0) and Sunday is last (6).
import calendar
my_cal = calendar.Calendar()
for x in my_cal.iterweekdays():
print(x)
Output:
0
1
2
3
4
5
6
This prints every weekday exactly once, starting with Monday. The numbers always mean 0=Monday through 6=Sunday; changing the first weekday changes only the sequence.
Run this code, start the week on a different day, display weekday names and solve self-checking exercises in the companion notebook.
Colab runs in your browser; no additional Python packages are needed.
The method belongs to a calendar.Calendar object. Use Calendar(firstweekday=0) to choose the first weekday, then call iterweekdays(). It takes no arguments and produces seven integers from 0 to 6, once each.
my_cal = calendar.Calendar(firstweekday=0)
weekday_iterator = my_cal.iterweekdays()
| Number | Weekday | Constant |
|---|---|---|
| 0 | Monday | calendar.MONDAY |
| 1 | Tuesday | calendar.TUESDAY |
| 2 | Wednesday | calendar.WEDNESDAY |
| 3 | Thursday | calendar.THURSDAY |
| 4 | Friday | calendar.FRIDAY |
| 5 | Saturday | calendar.SATURDAY |
| 6 | Sunday | calendar.SUNDAY |
You can also review Python iterators and the calendar module before moving to the examples.
Pass firstweekday=4 to the Calendar constructor. Friday appears first, followed by Saturday, Sunday, Monday, Tuesday, Wednesday and Thursday. The day numbers do not change.
import calendar
my_cal = calendar.Calendar(firstweekday=4)
for x in my_cal.iterweekdays():
print(x)
Output:
4
5
6
0
1
2
3
The instance-specific firstweekday setting is useful for rotating a weekly calendar without re-labeling dates.
calendar.day_name contains full weekday names, indexed from Monday (0). Combine it with the iterator so a person sees names instead of numbers.
import calendar
my_cal = calendar.Calendar(firstweekday=4)
for day in my_cal.iterweekdays():
print(day, calendar.day_name[day])
Output:
4 Friday
5 Saturday
6 Sunday
0 Monday
1 Tuesday
2 Wednesday
3 Thursday
For shorter labels, use calendar.day_abbr[day] instead. These display names are locale-sensitive; the numbered weekdays remain stable.
import calendar
my_cal = calendar.Calendar(firstweekday=0)
for day in my_cal.iterweekdays():
print(calendar.day_abbr[day], end=" ")
Output:
Mon Tue Wed Thu Fri Sat Sun
Wednesday has index 2. This preserves the familiar weekly cycle while changing which day is listed first.
import calendar
my_cal = calendar.Calendar(firstweekday=2)
for day in my_cal.iterweekdays():
print(day)
Output:
2
3
4
5
6
0
1
The iterator can label the seven positions in a recurring schedule. This example assigns a task to every day, including weekends.
import calendar
my_cal = calendar.Calendar(firstweekday=0) # Starting with Monday
for day in my_cal.iterweekdays():
print("Assign task for day:", day)
Output:
Assign task for day: 0
Assign task for day: 1
Assign task for day: 2
Assign task for day: 3
Assign task for day: 4
Assign task for day: 5
Assign task for day: 6
For an actual working-day plan, filter out Saturday and Sunday as shown next.
On a typical Monday–Friday workweek, weekday numbers 0 to 4 are working days. This condition works even when the calendar begins on Sunday or Friday.
import calendar
my_cal = calendar.Calendar(firstweekday=6)
for day in my_cal.iterweekdays():
if day < 5:
print(calendar.day_name[day], "- working day")
Output:
Monday - working day
Tuesday - working day
Wednesday - working day
Thursday - working day
Friday - working day
Notice that the iterator starts with Sunday, but the filter excludes Sunday and Saturday. For countries with other weekend patterns, change the condition to reflect the applicable workweek.
iterweekdays() returns an iterator, not a list. Wrap it in list() when you want to print, index, or reuse the weekday sequence.
import calendar
my_cal = calendar.Calendar(firstweekday=6)
weekdays = list(my_cal.iterweekdays())
print(weekdays)
print("First:", weekdays[0])
print("Total:", len(weekdays))
Output:
[6, 0, 1, 2, 3, 4, 5]
First: 6
Total: 7
A new call to my_cal.iterweekdays() creates a fresh iterator. A saved list is useful for repeated passes.
Use setfirstweekday() on an existing Calendar instance rather than making another object. The class method changes only that calendar object.
import calendar
my_cal = calendar.Calendar()
print(list(my_cal.iterweekdays()))
my_cal.setfirstweekday(calendar.SUNDAY)
print(list(my_cal.iterweekdays()))
print("First day number:", my_cal.getfirstweekday())
Output:
[0, 1, 2, 3, 4, 5, 6]
[6, 0, 1, 2, 3, 4, 5]
First day number: 6
Important distinction: my_cal.setfirstweekday(...) sets the weekday on a particular object. The module-level calendar.setfirstweekday(...) configures module-level calendar formatting and is not required for this instance example.
To build a calendar display whose first column is Sunday, use the named constant calendar.SUNDAY. Named constants are clearer than remembering their numbers.
import calendar
my_cal = calendar.Calendar(firstweekday=calendar.SUNDAY)
print([calendar.day_name[d] for d in my_cal.iterweekdays()])
Output:
['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
A dictionary maps each weekday number to a task. Iterate in calendar order to display the tasks as a weekly schedule rather than sorting task names.
import calendar
tasks = {
calendar.MONDAY: "Review work",
calendar.TUESDAY: "Write code",
calendar.WEDNESDAY: "Test changes",
calendar.THURSDAY: "Update notes",
calendar.FRIDAY: "Share report",
calendar.SATURDAY: "Rest",
calendar.SUNDAY: "Plan next week",
}
my_cal = calendar.Calendar(firstweekday=calendar.MONDAY)
for day in my_cal.iterweekdays():
print(f"{calendar.day_name[day]}: {tasks[day]}")
Output:
Monday: Review work
Tuesday: Write code
Wednesday: Test changes
Thursday: Update notes
Friday: Share report
Saturday: Rest
Sunday: Plan next week
Because dictionary keys are weekday numbers, a different start day rotates the output without changing which task belongs to Monday or Sunday.
An iterator yields values one at a time. Once consumed, it cannot be restarted; request a new iterator by calling iterweekdays() again, or save the items in a list.
import calendar
my_cal = calendar.Calendar()
days = my_cal.iterweekdays()
print(next(days))
print(list(days))
print(list(days))
print(list(my_cal.iterweekdays()))
Output:
0
[1, 2, 3, 4, 5, 6]
[]
[0, 1, 2, 3, 4, 5, 6]
After next(days) consumes Monday, the next list(days) contains Tuesday through Sunday. The second list is empty because that iterator has finished.
Calendar.iterweekdays() describes the order of weekday columns for one full week. In contrast, calendar.weekday(year, month, day) gives the weekday for a specific date. Neither method returns the dates that belong to a particular month.
import calendar
from datetime import date
my_cal = calendar.Calendar(firstweekday=calendar.SUNDAY)
print("Week order:", list(my_cal.iterweekdays()))
sample_date = date(2026, 1, 1)
print("Date weekday:", calendar.weekday(sample_date.year, sample_date.month, sample_date.day))
print("Date name:", calendar.day_name[sample_date.weekday()])
Output:
Week order: [6, 0, 1, 2, 3, 4, 5]
Date weekday: 3
Date name: Thursday
For month-by-month dates, the calendar module overview explains other APIs, such as itermonthdates() and monthcalendar(). Use iterweekdays() when you specifically need header order or a recurring seven-day schedule.
| Issue | Cause | Fix |
|---|---|---|
<calendar.Calendar object ...> or an iterator object printed | Printing the object rather than iterating it | Use for day in my_cal.iterweekdays(): or list(...) |
| Empty result on the second iteration | The saved iterator has been consumed | Call iterweekdays() again or save list(...) |
NameError: name 'calendar' is not defined | Forgot import calendar | Import calendar before constructing the object |
TypeError from an invalid start weekday | The setting is not a suitable integer | Use 0–6 or calendar.MONDAY through calendar.SUNDAY |
Expected Friday to become 0 | Confusing display position with weekday identity | Friday is always 4; firstweekday rotates the order |
| Weekend days are included in a schedule | The iterator always yields all seven days | Filter by weekday number according to your working-week rules |
Passing an out-of-range integer to the Calendar setting may normalize it modulo seven; do not rely on invalid inputs in your own interfaces. Explicitly validate user choices from 0 to 6.
import calendar
start_day = 8
if not isinstance(start_day, int) or not 0 <= start_day <= 6:
print("Choose a weekday number from 0 to 6")
else:
my_cal = calendar.Calendar(firstweekday=start_day)
print(list(my_cal.iterweekdays()))
Output:
Choose a weekday number from 0 to 6
Try these mini-challenges before checking the notebook solutions. The companion Colab practice notebook contains runnable examples, guided tasks and assertions that confirm your answers.
import calendar
my_cal = calendar.Calendar(firstweekday=calendar.TUESDAY)
days = list(my_cal.iterweekdays())
print(days)
assert days == [1, 2, 3, 4, 5, 6, 0]
assert sorted(days) == list(range(7))
Output:
[1, 2, 3, 4, 5, 6, 0]
The assertions silently pass when the result is correct. If an assertion fails, Python raises AssertionError; the notebook includes further exercises with a separate answer section.
No. It returns an iterator. Wrap the result with list() to obtain a list of weekday integers.
No. Monday remains 0, Tuesday remains 1, and Sunday remains 6. Only the order is rotated.
Construct calendar.Calendar(firstweekday=calendar.SUNDAY), or call my_cal.setfirstweekday(calendar.SUNDAY) on an existing instance.
Use calendar.day_name[day] inside the loop, or calendar.day_abbr[day] for abbreviations.
No. It gives a weekday display order. Use calendar.weekday(year, month, day) or datetime.date.weekday() for a specific date.
No. It returns seven weekdays. Apply a condition to select the days that belong to your workweek.
No. calendar is included in Python's standard library, so all examples here work in a standard Python 3 environment or Colab.
next() and repeated iteration work.Want to experiment? Return to the Colab and GitHub practice links.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.