Python calendar.iterweekdays(): Weekday Numbers and Examples

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.

Practice the weekday examples

Run this code, start the week on a different day, display weekday names and solve self-checking exercises in the companion notebook.

Open calendar iterweekdays practice notebook in Google Colab View notebook on GitHub

Colab runs in your browser; no additional Python packages are needed.

Syntax and weekday numbering

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()
NumberWeekdayConstant
0Mondaycalendar.MONDAY
1Tuesdaycalendar.TUESDAY
2Wednesdaycalendar.WEDNESDAY
3Thursdaycalendar.THURSDAY
4Fridaycalendar.FRIDAY
5Saturdaycalendar.SATURDAY
6Sundaycalendar.SUNDAY

You can also review Python iterators and the calendar module before moving to the examples.

Start the week on Friday

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.

Convert weekday numbers to names

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 

Start the week on Wednesday

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

Task scheduling example

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.

Select working days only

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.

Convert the iterator to a list

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.

Change the start day on an existing Calendar

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.

Sunday-first calendars

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']

Assign different tasks to weekdays

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.

Iterator behavior and reuse

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.

iterweekdays() vs weekday()

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.

Common errors and troubleshooting

IssueCauseFix
<calendar.Calendar object ...> or an iterator object printedPrinting the object rather than iterating itUse for day in my_cal.iterweekdays(): or list(...)
Empty result on the second iterationThe saved iterator has been consumedCall iterweekdays() again or save list(...)
NameError: name 'calendar' is not definedForgot import calendarImport calendar before constructing the object
TypeError from an invalid start weekdayThe setting is not a suitable integerUse 0–6 or calendar.MONDAY through calendar.SUNDAY
Expected Friday to become 0Confusing display position with weekday identityFriday is always 4; firstweekday rotates the order
Weekend days are included in a scheduleThe iterator always yields all seven daysFilter 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

Practice exercises

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.

  1. Create a week that starts on Tuesday and print the resulting list of numbers.
  2. Print abbreviated weekday names for a week that starts on Sunday.
  3. Create a list containing only Monday–Friday in the order returned by a Friday-first calendar.
  4. Check that any valid start day produces seven distinct weekday numbers.
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.

Frequently asked questions

Does iterweekdays() return a list?

No. It returns an iterator. Wrap the result with list() to obtain a list of weekday integers.

Does the firstweekday parameter renumber the weekdays?

No. Monday remains 0, Tuesday remains 1, and Sunday remains 6. Only the order is rotated.

How do I start the calendar on Sunday?

Construct calendar.Calendar(firstweekday=calendar.SUNDAY), or call my_cal.setfirstweekday(calendar.SUNDAY) on an existing instance.

How do I obtain weekday names instead of numbers?

Use calendar.day_name[day] inside the loop, or calendar.day_abbr[day] for abbreviations.

Can iterweekdays() tell me which day a date falls on?

No. It gives a weekday display order. Use calendar.weekday(year, month, day) or datetime.date.weekday() for a specific date.

Does iterweekdays() skip weekends automatically?

No. It returns seven weekdays. Apply a condition to select the days that belong to your workweek.

Do I need to install a package for this code?

No. calendar is included in Python's standard library, so all examples here work in a standard Python 3 environment or Colab.

Want to experiment? Return to the Colab and GitHub practice links.

Back to top ↑




Subscribe to our YouTube Channel here



plus2net.com







Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
Python Tkinter Video Tutorials
✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer