python in the count and index

str = [1,2,3,4,5] # define a list
STR = list. 3 # . 3
STR
[. 1, 2,. 3,. 4,. 5,. 1, 2,. 3,. 4,. 5,. 1, 2,. 3 ,. 4,. 5]
str.count (1) the number # 1 appears in str
. 3
str.index (2) in the # 2 position of the first occurrence of str
1
str.index (2,7,12) from # index in find (7, 12) in the position of the first occurrence of 2
11
str.index (2,7,10) # find the location of the first occurrence of 2 from the index in (7,10), the find will not an error

Traceback (most recent call last):
File "<pyshell#31>", line 1, in
str.index(2,7,10)
ValueError: 2 is not in list

Guess you like

Origin www.cnblogs.com/icodeworld/p/11295236.html