Test Index

CBSE Class 12 Computer Science 2025 Paper Set 4 Get it on Google PlayDownload on the App Store

© 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 found
Key point: 6 would be the answer for game.index("c"), and -1 is what find() returns, not index().
Answer:
Option D (ValueError)
© examsnet.com
Advertisements
Go to Question: