← Quiz: Context Managers: all 10 questions
Quiz: Context Managers · Question 8 of 10
What does this print? (code)
What does this print?
from contextlib import contextmanager
@contextmanager
def tag(name):
print(f"<{name}>", end="")
yield
print(f"</{name}>", end="")
with tag("p"):
print("hi", end="")
- A.hi<p></p>
- B.<p></p>hi
- C.<p>hi
- D.<p>hi</p>
Answer & explanation
Correct answer: <p>hi</p>
Setup runs before yield, then the body, then the code after yield.
Can you get the rest right without peeking?
Take the timed Quiz: Context Managers quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →