0
点赞
收藏
分享

微信扫一扫

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

萧萧雨潇潇 2022-02-15 阅读 71

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
举报

相关推荐

0 条评论