Question 6
Back to Exercise
What is the output of the following Python program?
s = "banana"
print(s.find("an"), s.rfind("an"), s.find("z"), s.count("a"), s.count("ana"))
- A 1 3 -1 3 2
- B 1 4 -1 3 1
- C 1 3 -1 3 1 Correct
- D 2 4 None 3 1
Correct Answer: Option C
"an" first appears at index 1 and last at index 3. count() is non-overlapping, so "ana" is counted once (the second would overlap the first).
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!