ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print(True + True, str(True) + '1', str(None), str([None]), repr('None'))- A. 2 True1 None [None] 'None'
- B. 2 True1 NoneType [None] 'None'
- C. 2 True 1 None [None] 'None'
- 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
- What is printed? python print(sorted([0.5, -0.0, 0.0, -1]))
- What is printed? python x = 10 16 print(float(x) == x, float(x + 1) == x, x + 1.0 == x, (x + 1) - x)
- What is printed? python print('%5s|%-5s|' % ('ab', 'cd'))
- What is printed? python print(len('%-8.3f|' % 3.14159), len('%08.3f' % -3.14159), '%08.3f' % -3.14159)
- What is printed? python import math print(math.prod([]), math.prod(range(1, 6)), math.lcm(range(1, 6)), math.lcm())
- What is printed? python print(list('ab') + ['c'] 2, 'ab' + 'c' 2, ('a',) 2)