ProgrammingHardGATE CS · Product-company placement

What is printed?

What is printed?
s = "racecar"
print(s.index("c"), s.rindex("c"), s.find("c", 3), s[::-1] is s, s.count("a", 2))
  1. A. 2 4 2 True 1
  2. B. 2 4 4 False 1
  3. C. 2 4 4 True 2
  4. D. 2 5 4 False 1

Correct answer: B. 2 4 4 False 1

index finds the first 'c' (2), rindex the last (4); find with start 3 skips index 2 and finds 4. Slicing always builds a new string here, so `is` is False... and count from index 2 sees only the 'a' at index 5.

More Python Programming questions

Exams that ask this topic