Finds the index of an element of the list in python

1, a method of: using the characteristics of the array itself a.index (target), where a is the target list, target is the index corresponding to the desired value. code show as below:

2 shows index. However, if there are a plurality of elements 76, this method can only obtain a match for both the first index value of the index.

2. Method 2: Using enumerate function.

code show as below:

operation result:

Extended Information:

By operating the index python (Python sequence containing 6 built: a list of tuples, strings, Unicode strings, buffer objects, xrange object):

1, the index:

Law exists between a positive and negative index index: when the number of positive index + = absolute value of the negative index of the element, they refer to the same element.

2, slice:

Fragmentation element for intercepting a range by: specify starting section (right-left opening and closing section, comprising a left index value corresponding to an element, but does not include the right index values ​​corresponding to the measured element).

Fragment including the start index of the corresponding elements, but not including the stop element corresponding to the index, the index is out of range may occur but will only take a positive value to the last element. If the index is negative, it means that from the beginning of the rightmost element, then the need to avoid index out of bounds.

Published 136 original articles · won praise 71 · views 160 000 +

Guess you like

Origin blog.csdn.net/u012308586/article/details/104960447