ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print('%.3s' % 'abcdef' + '|' + '%-4d|' % 7 + '%04.1f' % 2.25)- A. abc|7 |02.2
- B. abc|7 |2.2
- C. abc|7 |02.3
- D. abd|7 |02.2
Correct answer: A. abc|7 |02.2
%.3s keeps the first three characters. %-4d left-aligns 7 in four columns, and 2.25 is an exact tie that rounds to even 2.2, padded to four characters with a leading zero.
More Python Programming questions
- What is printed? python x = 0xFF print(x >> 4, x & 0xF0, x ^ 0x0F, ~x & 0xFF)
- What is printed? python print(int.frombytes((65).tobytes(1, 'big') 3, 'big'), 65 65 65, bytes([65] 3).decode())
- What is printed? python print(max(['10', '9'], key=len), max(['10', '9']), max([10, 9], key=str))
- What is printed? python print(10 == 10.0 and 'a' == 'a', 1 < 2 or 1 / 0)
- What is printed? python print(sum(x for x in range(1, 101) if x % 3 == 0 or x % 5 == 0))
- What is printed? python print(int(float(253)) == 253, float(253 + 1) - 253, (253 + 1) - 253)