Question 3
Back to Exercise
What is the output of the following Python program?
def register(func):
print("registering", func.__name__)
return func
@register
def a(): return "A"
@register
def b(): return "B"
print("start")
print(a() + b())
- A start registering a registering b AB
- B registering a registering b start AB Correct
- C start AB
- D registering a start registering b AB
Correct Answer: Option B
Decorators run as each def executes, before the rest of the program; register returns the functions unchanged.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!