What will be the output of the following Python function? print((20, "*") * 2)
2026
What will be the output of the following Python function?
print((20, "*") * 2)
- A.
((20, '*'), (20, '*'))
- B.
(20, '*', 20, '*')
- C.
(20, 20, '*', '*')
- D.
[20, '*', 20, '*']
Attempted by 272 students.
Show answer & explanation
Correct answer: B
Concept: For a sequence (tuple or list), the * operator with an integer n performs repetition: seq * n returns a new sequence formed by concatenating n copies of seq, end to end. It keeps the original element order, adds no nesting, and preserves the container type (a tuple stays a tuple).
Application: Trace (20, '*') * 2 step by step:
The operand is the tuple (20, '*') and the multiplier is the integer 2.
Repetition by 2 means two copies joined: (20, '*') + (20, '*').
Concatenation lays the elements out at a single level in order: 20, '*', 20, '*'.
The container stays a tuple, so the result is (20, '*', 20, '*').
Cross-check: The result has 2 × 2 = 4 elements, which matches. No outer parentheses are added (no nesting), the order is unchanged (no sorting by type), and the brackets stay round (still a tuple, not a list). Hence the output printed is (20, '*', 20, '*').