0

Problem with Python you must have faced !

Sololearn said in the range lesson of Python that "The call to list is necessary because 'range' by itself creates a 'range object', and this must be converted to a list if you want to use it as one." but when i type like : print(range(4)) ---> it inputs [0,1,2,3] that indicates that i don't need to call to the list ,but why they claimed that ?

15th Apr 2017, 2:20 PM
thành long nguyễn
thành long nguyễn - avatar
1 Odpowiedź
+ 5
range is not of list type, i.e. you can't treat it like one. You may not add it to another list, you can't assign value to it or any of its elements, etc. However, as an ordered sequence, it can be called - range(4)[2] equals 2. It can be iterated upon (for i in range(100) and it can be used as a generator: list(range(100))
15th Apr 2017, 3:05 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar