0

list(range(10)) replace the typical []to declare a list?

The are the same....right? The lesson did not introduce this

11th Jul 2017, 12:59 AM
Apollo
3 odpowiedzi
+ 2
Anyway, you can declare an empty list with list(range(0))... even if that's less efficient and readable than use [] ^^ And for Python2 users, don't forgot that range() will return a list, while Python3 return an iterator, as the Python2 xrange() function which was renamed in Python3 and original one deprecated...
11th Jul 2017, 5:48 AM
visph
visph - avatar
0
Not really. Listname = [] will declare an empty list. So if you print(Listname) you will get []. If you use ListR = list(range(10)) and you print(ListR) you will get 0 through 9 in the list. So it depends on what you want/need to do.
11th Jul 2017, 1:24 AM
Jim Tully
Jim Tully - avatar
0
Well, they are not really the same! I f you want to create a list of random objects, or objects chosen by you that are in a random order, than you may want to use: listname = [...] But if you want a list of consecutive numbers, you really want to use: listname = list(range(100)) instead of typing all the numbers: listname = ['0', '1', '2', '3', '4', '5', '6', etc...]
6th Aug 2017, 7:43 PM
Rotalex
Rotalex - avatar