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)

  1. A.

    ((20, '*'), (20, '*'))

  2. B.

    (20, '*', 20, '*')

  3. C.

    (20, 20, '*', '*')

  4. 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:

  1. The operand is the tuple (20, '*') and the multiplier is the integer 2.

  2. Repetition by 2 means two copies joined: (20, '*') + (20, '*').

  3. Concatenation lays the elements out at a single level in order: 20, '*', 20, '*'.

  4. 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, '*').

Explore the full course: Rssb Senior Computer Instructor