What will be the output of the following Python code?

#generator
def f(x):
    yield x+1
g=f(8)
print(next(g))

a) 8
b) 9
c) 7
d) Error

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

  1. b
    Explanation: The code shown above returns the value of the expression x+1, since we have used to keyword yield. The value of x is 8. Hence the output of the code is 9.

Leave a Comment