Next, Function or Method ?
Wed Apr 26, 2017 · 74 words

While in Python 2 it was possible to use both the function next() and the .next() method to iterate over the resulting values of a generator, the later has been removed with the introduction of Python 3.

Consider the sample generator:

def sample_generator():
    yield "a"
    yield "b"
    yield "c"

In Python 2:

a = sample_generator()
print(next(a)) # prints 'a'
print( # prints 'b'

But in Python 3:

print(next(a)) # prints 'a'
print( # AttributeError

back · he thought · he could · so he did · main