ProgrammingModerateGATE CS · Product-company placement

What is printed?

What is printed?
s = "banana"
print(s.replace("a", "o", 2), s.upper().count("A"), s[::2], s.startswith(("x", "ba")))
  1. A. bonono 3 bnn True
  2. B. bonona 3 aaa True
  3. C. bonona 3 bnn True
  4. D. bonona 3 bnn False

Correct answer: C. bonona 3 bnn True

The count argument limits replace to the first 2 a's. s[::2] takes indices 0, 2, 4 ('b', 'n', 'n'). startswith accepts a tuple of prefixes and is True if any matches.

More Python Programming questions

Exams that ask this topic