ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print(len('ab' * 3 * 0 + 'c'), ('%5.2f' % 3.14159).strip(), '%-5s|' % 'ab', '%05d' % -42)- A. 1 3.14 a| -0042
- B. 1 3.14 ab |-42
- C. 3 3.14 ab | -0042
- D. 1 3.14 ab | -0042
Correct answer: D. 1 3.14 ab | -0042
'ab' * 3 * 0 is the empty string, so the length is 1. %-5s left-aligns 'ab' in five columns, and %05d zero-pads -42 to width five with the sign first, giving -0042.
More Python Programming questions
- What is printed? python print(-7 // 2, -7 % 2, -7 // 2 2 + -7 % 2)
- What is printed? python print(7 // -2, -7 // 2, 7 % -2, divmod(-7, -2))
- What is printed? python print(round(2.5), round(3.5), round(-0.5), round(0.5 + 1e-16))
- What is printed? python print('ß'.upper(), 'Dž'.lower(), len('ß'.upper()), 'İ'.lower() == 'i')
- What is printed? python import math print(f'{-0.0}', -0.0 == 0.0, math.copysign(1, -0.0))
- What is printed? python print(1 == 1.0, hash(1) == hash(1.0), {1: 'a'}[1.0], True + 1.0)