ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print(len(f'{3.5:>8.2f}'), f'{-3.5:08.1f}', f'{12:#06x}', f'{7:+05d}')- A. 8 -0003.5 0x000c +0007
- B. 8 -00003.5 0x0c +0007
- C. 8 -00003.5 0x000c +0007
- D. 7 -00003.5 0x000c +0007
Correct answer: C. 8 -00003.5 0x000c +0007
The width 8 spec pads 3.50 to eight characters. With zero padding the sign comes first, and # with x keeps the 0x prefix inside the six-character width. The + with zero padding gives +0007.
More Python Programming questions
- What is printed? python print('abc'.encode() == b'abc', b'abc'.decode() == 'abc', 'é'.encode('utf-8') == b'xc3xa9', len(b'xc3xa9'.decode()))
- What is printed? python print('%.3s' % 'abcdef' + '|' + '%-4d|' % 7 + '%04.1f' % 2.25)
- 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)