ProgrammingVery hardTCS NQT · Infosys
What is printed?
What is printed?
print(f'{1234.5:,.2f}', f'{0.000123:.2e}', f'{-0.0:+.1f}', f'{0x123456:_x}')- A. 1,234.50 1.23e-4 +0.0 12_3456
- B. 1,234.50 1.23e-04 -0.0 123456
- C. 1,234.50 1.23e-04 -0.0 12_3456
- D. 1,234.5 1.23e-04 -0.0 12_3456
Correct answer: C. 1,234.50 1.23e-04 -0.0 12_3456
The comma flag groups thousands and .2f keeps two decimals. The e format writes at least two exponent digits, and the sign of -0.0 is kept. The underscore flag groups hexadecimal digits in fours from the right, so 0x123456 becomes 12_3456.
More Python Programming questions
- What is printed? python print(int('٠٠٢٩') + 1, '٢٩'.isdigit())
- What is printed? python s = 'abc' print(s 0 == '', s[::-1][::-1] == s, s[1:-1] 2, s[-3:-1])
- What is printed? python print(sorted(['x10', 'x9', 'x1'], key=lambda s: int(s[1:])))
- What is printed? python print(0.1 3 == 0.3, 0.1 3 == 3 0.1, round(0.1 3, 1) == 0.3, 1 - 0.9 == 0.1)
- What is printed? python print('%s' % [1, 'a'], '%r' % 'a', '%5.2s|' % 'hello', '%c' % 65)
- What is printed? python print(hash(1.5) == hash(3/2), hash(True) == hash(1), {0: 'x', False: 'y'}, len({1: 'a', True: 'b', 1.0: 'c'}))