First page Back Continue Last page Overview Graphics

The range() Function

Programmers of other programming languages like C or C++ are used to a different kind of for loops:

for (i = 0; i < n; i++) printf("%d, ",i);

Such a behaviour can be imitated in Python with the help of the range() function:

>>> range(5)

[0, 1, 2, 3, 4]

>>> range(3,7)

[3, 4, 5, 6]

>>> range(3,20,4)

[3, 7, 11, 15, 19]