ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print(format('x', '>4') + '|' + format(3.14159, '^9.2f') + '|' + format(42, '+') + '|' + format(1234567, ','))- A. x| 3.14 |+42|1234567
- B. x| 3.14 |+42|1,234,567
- C. x| 3.14 |+43|1,234,567
- D. x| 3.14 |+42|12,34,567
Correct answer: B. x| 3.14 |+42|1,234,567
Centering pads the leftover space with more on the right when the total is odd, which gives two spaces left and three right in a width of nine. The + sign prints for positive numbers, and the comma flag groups digits by thousands.
More Python Programming questions
- What is printed? python print('%d%%' % 50, '%x' % 255, '%o' % 8, '%e' % 12345.678)
- What is printed? python print(-(264) >> 3, -(264) // 8, -(264) % 10)
- What is printed? python print('a,b,,c'.split(','), 'a b c'.split(), 'a b c'.split(' '), ' x '.strip(), 'x,'.split(','))
- What is printed? python print(sorted(['Bb', 'aA', 'bb', 'AA'], key=str.lower))
- What is printed? python print(-7 % 3, 7 % -3, -7 // 3, 7 // -3)
- What is printed? python print(pow(-7, 3, 5), (-7) 2 % 5, -7 2 % 5)