Home »
MCQs »
Python MCQs
The list.index(x[, start[, end]]) is used to ___
17. The list.index(x[, start[, end]]) is used to ___.
- Return zero-based index in the list
- Raises a ValueError if there is no such item
- Both A and B
- None of the mentioned above
Answer: C) Both A and B
Explanation:
The index(x[, start[, end]]) is used to return the zero-based index in the list of the first item whose value is equal to x. index() is used to return the zero-based index in the list of the first item whose value is equal to x. If there is no such item, the method raises a ValueError. The optional arguments start and end are interpreted in the same way as in the slice notation and are used to restrict the search to a specific subsequence of the list of elements. Instead of using the start argument to calculate the index, the returned index is computed relative to the beginning of the full sequence.