Tsallaka zuwa abun ciki
Justice Tech School

The range() Function

range(stop) counts from 0 up to stop minus 1. range(start, stop) begins at start and range(start, stop, step) moves by step, which can be negative to count down. range does not build a list: wrap it in list() to see the numbers.

Example
print(list(range(5)))
print(list(range(2, 8)))
print(list(range(0, 20, 5)))
print(list(range(5, 0, -1)))
for i in range(3):
    print("round", i)

Result

[0, 1, 2, 3, 4]
[2, 3, 4, 5, 6, 7]
[0, 5, 10, 15]
[5, 4, 3, 2, 1]
round 0
round 1
round 2

Exercise

Count from 10 down to 1.

list(range(10, 0, ))

Quiz Test

What is the last number in range(5)?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.