ProgrammingModerateTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
nums = [3, 3, 1]
print(nums.index(3), nums.count(3), [i for i, v in enumerate(nums) if v == 3])
  1. A. 1 2 [0, 1]
  2. B. 0 3 [0, 1, 2]
  3. C. 0 2 [0, 1, 2]
  4. D. 0 2 [0, 1]

Correct answer: D. 0 2 [0, 1]

index returns the first position of the value, so 3 is at index 0. count gives 2 occurrences. The enumerate list shows both positions 0 and 1.

More Python Programming questions

Exams that ask this topic