[Tutor] Range command

Alan Gauld alan.gauld at yahoo.co.uk
Wed Jun 26 19:44:07 EDT 2019


On 27/06/2019 00:07, Brick Howse via Tutor wrote:
> Hello all, 
> 
> New to programming and I noticed the range command did not function like it does in the tutorial. 
> For example,
> I type 
>>>>> range(5, 10)
> And the output is 
> range(5, 10)

You have a Python 2 tutorial but are using Python 3.

In Python 3 range has changed and returns a fancy kind of object
(a range) that you don't really need to know about. If you really
want the values convert it to a list:

>>> list(range(5,10))

> Any suggestions is greatly appreciated.

To avoid any similar confusion either find a Python 3 tutorial or
download Python 2 and use it. Once you know Python 2 converting to
Python 3 is not hard. But it is probably best just to learn Python 3
from the start!

Thee are quite a few of these kinds of changes between Python 2 and 3.
For experienced programmers they are "A Good Thing" because they make
Python more efficient and more consistent in the way it works.
But for a beginner they just seem bizarre and unintuitive.  For
now, just accept them and eventually you will understand why
they exist.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list