python List count()方法 list里面元素出现的次数

count() 统计某个元素在list中出现的次数

list.count(obj)
testlist = [123, 'abc', 'cdf', 'abc', 123, 123]

print("Count for 123 : ", testlist.count(123)) 
print("Count for abc : ", testlist.count('abc'))

结果

Count for 123 :  3
Count for abc :  2

猜你喜欢

转载自blog.csdn.net/stellao_o/article/details/122935365