ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print(('a' 'b' 'c').upper(), 'x' 'y' * 2, ('%d' % 3) * 2)- A. ABC xyy 33
- B. ABC xyxy 3
- C. ABCABC xyxy 33
- D. ABC xyxy 33
Correct answer: D. ABC xyxy 33
Adjacent string literals join at compile time, so 'a' 'b' 'c' is 'abc' and the upper() call applies to it. The * operator then applies to the joined 'xy' literal, giving xyxy.
More Python Programming questions
- What is printed? python print(1e16 == 1016, 1e16 + 1 == 1016 + 1, 1e16 + 2 == 1016 + 2, int(1e16) + 1)
- What is printed? python print('%.2e' % 0, '%.1f' % 2.25, '%.1f' % 2.35, '%5.1f|' % -0.04)
- What is printed? python x = 0.1 print((0.5).asintegerratio(), (0.1).asintegerratio()[1] == 255)
- What is printed? python import operator print(operator.index(5), operator.mod(-7, 3), operator.floordiv(-7, 3))
- What is printed? python print(sorted(['b', 'B', 'a', 'A'], key=lambda s: s.swapcase()))
- What is printed? python print(len(set('mississippi')), sorted(set('mississippi')))