Difference between "list (range (1, 10))" and "range (1, 10)"?

6

I asked this question here Formatting All the elements of a list in Python? .

In one of the answers, @CiganoMorrisonMendez put the following excerpt:

list(range(1, 10))

However, whenever I used Python , I used

range(1, 10)

Is this a conversion to list ? But does range no longer return a list ?

Update

I did a test on the command line and the result that was returned was this:

type(range(1, 10))
<type 'list'>
    
asked by anonymous 28.10.2015 / 19:59

1 answer

5

No.

range is a class that can be initialized with three arguments: start , end and increment. Therefore, a list is not equal.

It can generate a list if converted to list because it has the ability to be iterated.

In Python 2, the behavior was different. range effectively generated a list. In Python 3, the object is more like a generator.

    
28.10.2015 / 20:03