Count through a short range
python · static example
for number in range(1, 4):
print(number)`range(1, 4)` produces 1, 2, and 3.
Use a for loop to process each item in a sequence.
A loop repeats a block of code. A for loop is useful when processing each item in a collection or each value in a known range. The range() function generates a sequence of integers; its ending value is excluded.
python · static example
for number in range(1, 4):
print(number)`range(1, 4)` produces 1, 2, and 3.
1
2
3Labeled sample only — nothing was run on this page.
A student society wants to print a numbered checklist for five event volunteers.
What loop could produce the numbers 1 through 5?
Use `for number in range(1, 6):` and print `number` inside the indented loop. The stop value 6 is excluded.
What does `range(1, 4)` produce?
Pick an answer to check.