Question discussion

What is the output of the following Python code?def deco(f): def wrap(x): return f(x) + 1 return wrap @deco def g(x): return x * 2 print(g(…

1910Medium DSSSB TGT Computer Science 0 replies 1 views
0

What is the output of the following Python code?

def deco(f):
    def wrap(x):
        return f(x) + 1
    return wrap
 
@deco
def g(x):
    return x * 2
 
print(g(3))
  • A6
  • B7
  • C8
  • D5
Correct answer: B

Explanation

The decorator replaces g by wrap, so g(3) = (3 * 2) + 1 = 7.

Discussion 0

Nobody has replied yet. Start the discussion!