[Tutor] Displaying range in 3.0.1

Alan Gauld alan.gauld at btinternet.com
Fri May 29 00:07:28 CEST 2009


"Gregory Morton" <tyetheczar at hotmail.com> wrote

> I've been reading this Python 3.0.1 
> tutorial(http://docs.python.org/3.0/tutorial/controlflow.html),

Looks like a bug in the tutorial! In Python 3 you cannot just print a range
it is now a generator. Notice that in the tutorial the range() calls are 
not
shown at the >>> prompt.
They are not valid commands, the tutorial is just illustrating the expected
output from range for those values!

To see them you need to explicitly convert it to a list:

>>> list( range(0, 10, 3) )
 [0, 3, 6, 9]

>>> list( range(-10, -100, -30) )
 [-10, -40, -70]

HTH,


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/l2p/ 




More information about the Tutor mailing list