[Tutor] Displaying range in 3.0.1

Sander Sweers sander.sweers at gmail.com
Thu May 28 20:06:03 CEST 2009


2009/5/28 Gregory Morton <tyetheczar at hotmail.com>:
> I've been reading this Python 3.0.1
> tutorial(http://docs.python.org/3.0/tutorial/controlflow.html), and now I'm
> stuck at the second example in 4.3. This is what the example says the output
> should look like:

No it doen't but I can understand the confusion. More info below.

> range(5, 10)
>    5 through 9
>
> range(0, 10, 3)
>    0, 3, 6, 9
>
> range(-10, -100, -30)
>   -10, -40, -70
>
> But what I receive instead is the same as what I input (i.e. range(5,
> 10) just returns range(5, 10)).

What it returns is an *iterable* range object. Meaning you need to
iterate over it to get the values like in the first example.

for n in range(5,10):
    print(n)

Greets
Sander


More information about the Tutor mailing list