[91]: lst2.count(5)
Out[91]: 2
In [92]: lst2.count(8)
Out[92]: 0
原型:
def count(lst, value):
c = ...0
for x in lst:
if x == value:
c += 1
return c
小结:
index()和count()的时间复杂度是...;返回None
当给定的索引超过左边范围时,会在第0个元素前插入;超过右边的范围时,会在最后一个元素后插入
In [24]: lst1
Out[24]: [1, 3, 55, 2, 3, ...In [29]: lst1
Out[29]: ['x', 1, 3, 55, 2, 3, 4, 5, 6, 9, ['a', 'b'], 'xj', 'j']
3)list.extend()
接受一个可迭代对象...
In [226]: t.count(1)
Out[226]: 1
In [227]: t.index(1)
Out[227]: 0
In [228]: t.index