ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print(int('1_000') + int('0_1'), '1_000'.replace('_', '') == '1000', float('1_0.5_0'), '%.1f' % float('1_0.5_0'))- A. 1001 True 10.5 10.5
- B. 1000 True 10.5 10.5
- C. 1001 False 10.5 10.5
- D. 1001 True 105 10.5
Correct answer: A. 1001 True 10.5 10.5
Underscores between digits are accepted by int() and float() but not by a plain str comparison, so the replaced text is 1000. Adding int('0_1') gives 1 and the total is 1001.
More Python Programming questions
- What is printed? python print(round(-1234.5, -2), round(123456.0, -3), round(0.0, 2), round(1e-7, 7))
- What is printed? python print(str(1.0), str(1), str(1.0e0), str(10.0 0), repr(1e0))
- What is printed? python print(7 & ~1, 7 >> 1 << 1, (7 | 8) & 12, 6 ^ 3 ^ 3)
- What is printed? python print(sorted([(-1, 'a'), (1, 'b'), (-1, 'c')], key=lambda t: t[0], reverse=True))
- What is printed? python x = 'abc' y = x.upper() z = x.upper().lower() print(y, z == x, x.upper().upper() == y, len(y + z))
- What is printed? python print(int('0009'), float('009.50'), int(' -0 '), str(-0))