Test Index
CBSE Class 12 Computer Science 2025 Paper Set 4
© examsnet.com
Question : 3 of 37
Marks:
+1,
-0
Identify the correct output of the following code snippet :
game="Olympic2024"print(game.index("C"))
Solution:
Concept:
str.index(sub) returns the lowest index where sub is found. If sub is not present, it raises a ValueError. (str.find(sub) returns -1 in that case.)Explanation:String comparison is case-sensitive. "Olympic2024" contains a lowercase 'c' at index 6, but no uppercase 'C'. So index("C") fails:ValueError: substring not foundKey point: 6 would be the answer for
game.index("c"), and -1 is what find() returns, not index().Answer:Option D (ValueError)© examsnet.com
Go to Question: