ProgrammingModerateGATE CS · Product-company placement

What is printed?

What is printed?
print(repr([] or {} or 0 or ""), "a" and "b" or "c", "" and 1 or 0, not "0")
  1. A. 0 b 0 False
  2. B. [] b 1 False
  3. C. '' b 0 False
  4. D. '' c 0 True

Correct answer: C. '' b 0 False

`or` returns the first truthy operand or else the LAST operand (here ''). 'a' and 'b' gives 'b', which is truthy, so the or returns it. '' and 1 gives '', so the or returns 0. '0' is a non-empty string, hence truthy, and not makes it False.

More Python Programming questions

Exams that ask this topic