ProgrammingHardTCS NQT · Wipro pattern

What is printed?

What is printed?
print([1, 2, 3].index(2), 'abc'.index('bc'), (1, 2).index(2), [1, 2, 3].count(4))
  1. A. 1 1 1 0
  2. B. 2 1 1 0
  3. C. 1 1 1 1
  4. D. 1 2 1 0

Correct answer: A. 1 1 1 0

index returns the position of the first match, which is 1 for 2 in a list, 1 for bc in abc, and 1 for 2 in the tuple. count of an absent value is 0.

More Python Programming questions

Exams that ask this topic