|
OUTPUT:
range (0, 6)
Runtime errors:
Traceback (most recent call last): File "/home/6881218331a293819d2a4c16029084f9.py", line 13, in print (next (demo)) TypeError: list object is not an iterator
Note: the above runtime error clearly indicates that the Python range is not an iterator.
Since the range is iterative so we can get an iterator with it, but we cannot directly call next in the following. The example below explains it clearly
|
OUTPUT:
"listiterator object at 0x7f3f32a46450" 0
The range does not generate all the numbers it contains when we create it. It only gives the numbers that we get using the loop. Range has the following properties.
- Range objects are immutable, which means they cannot be changed again, so they can be used as an index in dictionaries.
- They have there are start and end arguments.
- the same range can be visited over and over
example
|
OUTPUT:
range (1, 31, 2) 1 2 11
Runtime error: because element 30 is missing, an error occurs
Traceback (most recent call last): File "/home/cddaae6552d1d9288d7c5ab503c54642.py", line 19, in print (demo.index (30)) ValueError: 30 is not in range