ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print(f"{12:>{5}}|{3.14159:.{2}f}|{'ab':*^6}")- A. 12|3.1|**ab**
- B. 12|3.14|**ba**
- C. 12|3.14|**ab**
- D. 12|3.14|*a b*
Correct answer: C. 12|3.14|**ab**
A nested replacement field such as {5} inside the spec supplies the width, so 12 is right-aligned in five columns. The precision {2} gives two decimals, and * fills the centred 'ab' in a width of six.
More Python Programming questions
- What is printed? python x = 12 print(x & -x, x ^ (x - 1), (x & (x - 1)) == 0, -x & x == x & -x)
- What is printed? python print((-5).tobytes(2, 'big', signed=True).hex(), int.frombytes(b'xffxfb', 'big', signed=True)…
- What is printed? python import math print(math.fsum([0.1] 10) == 1.0, sum([0.1] 10) == 1.0, math.isqrt(10 30 - 1))
- What is printed? python print(sorted(['pear', 'Fig', 'apple', 'banana', 'kiwi'], key=lambda s: (len(s), s.lower())))
- What is printed? python print(sorted([('b', 1), ('a', 1), ('c', 2)], key=lambda t: t[1], reverse=True))
- What is printed? python print(max(['abc', 'x', 'yz'], key=len), min(['b', 'B', 'a']))