ProgrammingModerateTCS NQT · Infosys

What is printed?

What is printed?
t = 'racecar'
print(t == t[::-1], t.find('car'), t.rfind('c'), t.replace('car', 'CAR', 1))
  1. A. True 4 4 raceCAT
  2. B. False 4 4 raceCAR
  3. C. True 4 5 raceCAR
  4. D. True 4 4 raceCAR

Correct answer: D. True 4 4 raceCAR

'racecar' reads the same both ways, and find returns the first 'car' at index 4. rfind('c') also finds index 4, and replace with a count of 1 changes only the first match.

More Python Programming questions

Exams that ask this topic