Identify the correct output of the following code snippet: game = ["A", "B",…

2025

Identify the correct output of the following code snippet: game = ["A", "B", "C"] print(game.index("C"))

  1. A.

    0

  2. B.

    2

  3. C.

    -1

  4. D.

    ValueError

Attempted by 1047 students.

Show answer & explanation

Correct answer: B

The code snippet defines a list game = ["A", "B", "C"]. The index() method is used to find the position of the first occurrence of a specified value in the list.

Step 1: The list has three elements: "A" at index 0, "B" at index 1, and "C" at index 2.

Step 2: The method game.index("C") searches for the value "C" in the list.

Step 3: Since "C" is found at index 2, the method returns 2.

Step 4: The print() function outputs the result, which is 2.

हिन्दी उत्तर: कोड स्निपेट में एक सूची game = ["A", "B", "C"] परिभाषित की गई है। index() विधि एक सूची में निर्दिष्ट मान की पहली उपस्थिति का स्थान खोजने के लिए उपयोग की जाती है।

चरण 1: सूची में तीन तत्व हैं: "A" इंडेक्स 0 पर, "B" इंडेक्स 1 पर, और "C" इंडेक्स 2 पर।

चरण 2: विधि game.index("C") सूची में "C" के लिए खोज करती है।

चरण 3: चूँकि "C" इंडेक्स 2 पर पाया जाता है, विधि 2 लौटाती है।

चरण 4: print() फ़ंक्शन परिणाम को आउटपुट करता है, जो 2 है।

Explore the full course: Bpsc