What will be the output of the following Python code?

def f(x):
    yield x+1
    print("test")
    yield x+2
g=f(10)
print(next(g))
print(next(g))

a) No output
b)11 test 12

c)11 test

d) 11

1 thought on “What will be the output of the following Python code?”

  1. b
    Explanation: The code shown above results in the output:
    11
    test
    12
    This is because we have used next(g) twice. Had we not used next, there would be no output.

Leave a Comment