Question:medium

Identify the correct output of the following code snippet:
game = "Olympic2024"
print(game.index("C"))

Show Hint

find() returns -1 if the substring is not found,
while index() raises an error.
Be cautious about letter case!
Updated On: Jan 14, 2026
  • 0
  • 6
  • -1
  • ValueError
Show Solution

The Correct Option is D

Solution and Explanation

For the string game = "Olympic2024", the objective is to locate the index of the character `"C"`.
It is important to note that Python's string indexing is case-sensitive.
The string `"Olympic2024"` includes a lowercase `"c"` at index 6, but it does not contain an uppercase `"C"`.
The index() method requires an exact match and will generate a ValueError if the specified substring is absent.
This differs from the find() method, which returns -1 upon failure to locate the substring, whereas index() raises an exception.
As an uppercase `"C"` is not present in the string, Python will consequently raise a ValueError.
Thus, the appropriate selection is option (D).
Was this answer helpful?
0