What is the output of the following Python code snippet?
def deco(f):
def w():
print('before')
f()
print('after')
return w
@deco
def hi():
print('hi')
hi()
-
A
hi
-
B
before
hi
after
Correct answer
-
C
before
after
-
D
Error
Correct answer
B. before
hi
after
6 views
Explanation
The decorator wraps the call with extra behaviour.
Doubts & discussion
Not sure why the answer is B? Ask here and get an explanation.
Ask a doubt about this MCQ