practicepython.in
python exercises
171 exercises

Daily #33 · 31 October 2026

Hello to nobody Hard

What does this print?

name = ""
print("Hi " + name if name else "there")
  1. AHi
  2. BHi there
  3. Cthere
  4. Draises TypeError
Show the answer

C: there

Why: if ... else inside an expression has the lowest priority, so it wraps everything to its left: ("Hi " + name) if name else "there". The name is empty, so the whole thing is "there". Brackets fix it: "Hi " + (name if name else "there").

Play today’s puzzle →