Home / CSE MCQs / Python MCQs :: Discussion

Discussion :: Python MCQs

  1. What is the output of the code shown below?

    def f(x):
        yield x+1
        print("test")
        yield x+2
    g=f(9)
  2. A.
    Error
    B.
    test
    C.

    test

    10

    12

    D.
    No output

    View Answer

    Workspace

    Answer : Option 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.


Be The First To Comment