What will be the output of the following Python program?

def numbers():
    yield 10
    yield 20

x = numbers()
print(next(x))
print(next(x))
                        

Options

  • A. 10 and 20
  • B. 20 and 10
  • C. 10 and 10
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

A. 10 and 20

Detailed Explanation

The yield keyword creates a generator. Each call to next() returns the next yielded value.