What will be the output of the following Python code?

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

a) Error
b) test

c)test 10 12

d) No output

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

  1. d
    Explanation: The code shown above will not yield any output. This is because when we try to yield 9, and there is no next(g), the iteration stops. Hence there is no output.

Leave a Comment