ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
print(True + True, str(True) + '1', str(None), str([None]), repr('None'))
  1. A. 2 True1 None [None] 'None'
  2. B. 2 True1 NoneType [None] 'None'
  3. C. 2 True 1 None [None] 'None'
  4. D. 3 True1 None [None] 'None'

Correct answer: A. 2 True1 None [None] 'None'

True behaves as 1 in arithmetic, so True + True is 2. str(True) is the text 'True', so appending '1' gives 'True1'. str(None) is 'None', and repr of a string adds quotes around it.

More Python Programming questions

Exams that ask this topic