In python2, range returns a list.
In Python3, range returns the object range . Object range does not add method. To fix, convert a range object to the list:
>>> myrange = list(range(10,100,10)) >>> myrange.append(200) >>> myrange [10, 20, 30, 40, 50, 60, 70, 80, 90, 200] )) >>> myrange = list(range(10,100,10)) >>> myrange.append(200) >>> myrange [10, 20, 30, 40, 50, 60, 70, 80, 90, 200]
The object range - it is an iterator. He deliberately avoids the formation of a list of all values, because it requires more memory, and often people use the range just to keep track of the counter - a use which does not require the simultaneous storage of the full list in the memory.
Of documents :
range type advantage over conventional list or tuple is that the range of the object will always be the same (small) amount of memory no regardless of band size, it represents (as it stores only the values โโof the start, stop, and step calculation of individual elements and subbands as required).