Nothing Runs Until You Ask
def counter():
print("generator body starting")
total = 0
for i in range(3):
total += i
yield total
print("before call")
g = counter()
print("after call, before first next")
print(next(g))
print(next(g))
What is the order of printed output?
Sign in to answer questions and track your progress
Sign In