1. Home
  2. Data Science
  3. Python
  4. What is the output of the following Python code snippet?

Added 25 Nov 2026

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()
  1. hi
  2. before hi after Correct answer
  3. before after
  4. Error

Correct answer

B. before hi after

6 views

MCQSEXAM

Explanation

The decorator wraps the call with extra behaviour.

Reference

Asked in: Python Interview Advanced Python

https://docs.python.org/3/library/index.html

Preparing for an exam?

Doubts & discussion

Not sure why the answer is B? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More Python MCQs

Practise all Python MCQs

Similar MCQs