Fetch any element through its index using index method

suggest change

index() returns first index of the matching value. Remember that arrays are zero-indexed.

my_array = array('i', [1,2,3,4,5])
print(my_array.index(5))
# 5
my_array = array('i', [1,2,3,3,5])
print(my_array.index(3))
# 3

Note in that second example that only one index was returned, even though the value exists twice in the array

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents