ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print('%d items' % 3, '%s' % 3.0, '%s' % None, '%r' % None)- A. 3 items 3 None None
- B. 3 items 3.0 None None
- C. 3 items 3.0 None 'No'
- D. 3 items 3.0 NoneType None
Correct answer: B. 3 items 3.0 None None
%d prints the integer, and %s uses str() on the float, which keeps the .0. None formats as None under both %s and %r.
More Python Programming questions
- What is printed? python print(10 3 == 1000.0, 1e3 == 10 3, type(10 3).name, type(1e3).name)
- What is printed? python print(bin(5), oct(8), hex(16), int('101', 2) + int('7', 8))
- What is printed? python print(sorted(['apple', 'Banana', 'cherry'], key=str.lower), sorted(['apple', 'Banana', 'cherry']))
- What is printed? python print(sum(range(5)) / len(range(5)), sum([1, 2, 3, 4]) // 4, 9 // 2 2 + 9 % 2)
- What is printed? python print(str(3) + str(4) == '34', 3 + 4 == 7, '3' + '4' == 7)
- What is printed? python print(len(''), len(' '), len('t'), ''.isspace())