ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
print('abcabc'.replace('abc', 'x', 1), 'aaaa'.replace('aa', 'b'), 'aaa'.replace('', '-'))
  1. A. xabc bb -a-a-
  2. B. xbc bb -a-a-a-
  3. C. xabc b -a-a-a-
  4. D. xabc bb -a-a-a-

Correct answer: D. xabc bb -a-a-a-

The count argument limits replacements to the first match. Non-overlapping replacement turns aaaa into bb, and replacing the empty string inserts a dash before and after each character.

More Python Programming questions

Exams that ask this topic