CS FundamentalsVery hardProduct-company placement · Python
What does this code print (lines joined by ' / ')?
What does this code print (lines joined by ' / ')?
def tag(name):
def deco(f):
print(name)
def w():
return f'<{name}>' + f() + f'</{name}>'
return w
return deco
@tag('b')
@tag('i')
def hi(): return 'hi'
print(hi())- A. b / i / <b><i>hi</i></b>
- B. i / b / <i><b>hi</b></i>
- C. b / i / <i><b>hi</b></i>
- D. i / b / <b><i>hi</i></b>
Correct answer: D. i / b / <b><i>hi</i></b>
Stacked decorators apply bottom-up: tag('i') wraps hi first (printing i), then tag('b') wraps that (printing b). At call time the outer b wrapper runs first, so the output is <b><i>hi</i></b>.
Practise more Software Engineering, Git and Cloud Basics questionsSoftware Engineering, Git and Cloud Basics: notes and key points
More Software Engineering, Git and Cloud Basics questions
- In this Observer code, handler a unsubscribes itself the first time it runs. What does it print (lines joined by ' / ')? python class Bus…
- A class gets its dependencies by calling ServiceLocator.get('Mailer') inside its methods, instead of receiving them through its…
- In a layered application, which pairing of the Repository and Unit of Work patterns is correct?
- How many of these statements about event sourcing are correct? 1. The append-only log of domain events is the source of truth, and current…
- Match each anti-pattern with its description. P. Golden hammer Q. Lava flow R. God object S. Cargo cult 1. One class knows and does far…
- A release burndown has stayed almost flat for three sprints, yet the team's velocity has been a steady 30 points per sprint. Which chart…