ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
x = 3.14159
print(f"{x:08.3f}|{x:>8.2e}|{42:#x}|{'ab'!r:>6}")- A. 0003.142|3.14e+00|42| 'ab'
- B. 0003.142|3.14e+00|0x2b| 'ab'
- C. 0003.142|3.14e+00|0x2a| 'ab'
- D. 3.142|3.14e+00|0x2a|'ab'
Correct answer: C. 0003.142|3.14e+00|0x2a| 'ab'
08.3f pads with zeros to width 8 and gives three decimals, so 0003.142. The e format gives 3.14e+00 in a width of 8. # with x adds the 0x prefix, and !r applies repr before the >6 right alignment.
More Python Programming questions
- What is printed? python print(f"{1234567.891:,.2f}", f"{255:b}", f"{-5:+d}")
- What is printed? python print('-'.join(map(str, [1, 2])) 2, ('ab' 3).count('ba'))
- What is printed? python print('a,,b,'.split(','), ' a b '.split(' '))
- What is printed? python print('1.2.3.4'.rsplit('.', 1), 'x'.partition('='), 'a=b=c'.partition('='))
- What is printed? python print(chr(ord('a') + 27), ord('Z') - ord('A'), chr(0x1F600) == 'U0001F600', len('U0001F600'))
- Which of the following Python operations on a built-in container is O(1) on average (independent of the container size)?