Question 5
Back to Exercise
What is the output of the following Python program?
def repeat(n):
def deco(func):
def wrapper(*args):
return [func(*args) for _ in range(n)]
return wrapper
return deco
@repeat(2)
def hi(name):
return "hi " + name
print(hi("Asha"), len(repeat(5)(len)("abc")))
- A hi Asha 5
- B ['hi Asha', 'hi Asha'] 3
- C TypeError
- D ['hi Asha', 'hi Asha'] 5 Correct
Correct Answer: Option D
repeat(5)(len) decorates len by hand; calling it with "abc" returns a list of five 3s, whose length is 5.
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!