ProgrammingModerateTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
print('-'.join(map(str, [1, 2])) * 2, ('ab' * 3).count('ba'))
  1. A. 1-21-2 2
  2. B. 1-2-1-2 2
  3. C. 1-21-2 3
  4. D. 1-21-2 1

Correct answer: A. 1-21-2 2

'-'.join gives '1-2', and multiplying by 2 concatenates two copies. 'ababab' contains 'ba' at positions 1 and 3, so count is 2.

More Python Programming questions

Exams that ask this topic