ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print('%s' % 'x' * 3, '%s' * 2 % ('a', 'b'), '%s' % ('x' * 3))- A. xxx ab xx
- B. xx ab xxx
- C. xxx ab xxx
- D. xxx ba xxx
Correct answer: C. xxx ab xxx
'%s' % 'x' is x and multiplying by 3 gives xxx. '%s' * 2 builds the format string %s%s before applying % to the pair, and the last one formats the three-x string directly.
More Python Programming questions
- What is printed? python print(3 'a' + 'b', 'c' 3 + 'd')
- What is printed? python print(int(3.7 10), int(0.7 10), 3.7 10 == 37, 0.7 10 == 7)
- What is printed? python print(sorted([True, 2, 1.5, False, -1]))
- What is printed? python print(1 if [] == [] is True else 0, [] is [], () is ())
- What is printed? python print(len(str(float(10300))), str(float(1022))[:4], float(1022) == 1022)
- What is printed? python print(10 // 3, 10 % 3, divmod(10, 3), (10 // 3) 3 + 10 % 3)