[Tutor] Question about a python finction
Alan Gauld
alan.gauld at yahoo.co.uk
Sat May 12 06:34:46 EDT 2018
On 12/05/18 06:40, peter wrote:
> range does not work the same for 2.7 and my 3.6.5. Seems they have
> changed the nature of range. It is a built in listed along with lists
> and tuples
You are correct in that it has changed slightly and now returns
a range object. but you can convert it to a list(or tuple) easily
>
>>>> list(range(10))
> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>
> >>> tuple(range(10))
> (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
Just as you have done here.
And if you don;t mneed the explicot list you can use it in a for loop
etc exactly as before:
for n in range(10):...
> ...range(10) will not work with python3.6.5
Yes it will, it just returns a slightly different value that
you must explicitly convert to a list if needed.
--
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