ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
print(1 if 0 else 2 if 3 else 4, 0 or '' or 'z', 0 and 'z')
  1. A. 2 0 0
  2. B. 4 z 0
  3. C. 2 z False
  4. D. 2 z 0

Correct answer: D. 2 z 0

The conditional chain picks 2 because 0 is falsy and 3 is truthy. 'or' returns the first true operand, 'z'. 'and' stops at the first falsy operand, 0.

More Python Programming questions

Exams that ask this topic