Informatics Practices

For a given list

L = [1, 2, 3, 4, 5, 6]

the index of element 4 will be:

Assertion (A): The index of element 4 will be 3 or -3.

Reasoning (R): Python list supports forward and backward indexing with -1 to given to left most and 0 to right most element.

  1. Both A and R are true and R is the correct explanation of A.
  2. Both A and R are true but R is not the correct explanation of A.
  3. A is true but R is false.
  4. A is false but R is true.

Python List Manipulation

3 Likes

Answer

A is true but R is false.

Explanation
The index of element 4 in the list L = [1, 2, 3, 4, 5, 6] is 3. Additionally, the index -3 refers to the element 4 when counting from the end of the list. Python lists support both forward (positive) and backward (negative) indexing with -1 referring to the rightmost element and 0 referring to the leftmost element.

Answered By

3 Likes


Related Questions