Why is the range object "not an iterator"?
generator, python, python-3.x
Solution
`range` returns an iterable, not an iterator. It can make iterators when iteration is necessary. It is not a generator.
A generator expression evaluates to an iterator (and hence an iterable as well).
Problem
I wrote this and expected `0`: ``` >>> x = range(20) >>> next(x) ``` Instead I got: TypeError: 'range' object is not an iterator But I thought it was a generator? The initial answer yielded the same thing I initially said to myself: it's an iterable, not an interator. But then, that wouldn't explain why this works, if both are simply generators: ``` >>> x = (i for i in range(30)) >>> next(x) 0 ```