ProgrammingModerateTCS NQT · Wipro pattern

What is printed?

What is printed?
print(list('ab') + ['c'] * 2, 'ab' + 'c' * 2, ('a',) * 2)
  1. A. ['a', 'b', 'c', 'c'] abcc ('a', 'a')
  2. B. ['a', 'b', 'cc'] abcc ('a', 'a')
  3. C. ['a', 'b', 'c', 'c'] acc ('a', 'a')
  4. D. ['a', 'b', 'c', 'c'] abcc ('a',)

Correct answer: A. ['a', 'b', 'c', 'c'] abcc ('a', 'a')

Multiplication binds tighter than +, so ['c'] * 2 gives two list items and 'c' * 2 gives 'cc'. A one-element tuple repeated twice is a two-element tuple.

More Python Programming questions

Exams that ask this topic