ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
print('xy'.replace('', '-'))
  1. A. xy
  2. B. -x-z-
  3. C. -x-y-
  4. D. x-y-z

Correct answer: C. -x-y-

An empty pattern matches before, between and after each character, so replace inserts - at every position including both ends.

More Python Programming questions

Exams that ask this topic