ProgrammingHardTCS NQT · Wipro pattern

What is printed?

What is printed?
s = 'x' * 3
print(s * -1 == '', s.replace('x', 'xy', 2), s.count('xx'), s.index('x', 1))
  1. A. True xyxyxx 1 1
  2. B. False xyxyx 1 1
  3. C. True xyxyx 2 1
  4. D. True xyxyx 1 1

Correct answer: D. True xyxyx 1 1

A negative repeat count gives the empty string. replace with a count of 2 changes only the first two x characters, and count('xx') does not overlap, so it finds one match.

More Python Programming questions

Exams that ask this topic