list.count(obj)
本页内容
Python3 List count()方法
描述
count() 方法用于统计某个元素在列表中出现的次数。
语法
count()方法语法:
示例
list.count(obj)
参数
- obj -- 列表中统计的对象。
返回值
返回元素在列表中出现的次数。
以下实例展示了 count()函数的使用方法:
示例
#!/usr/bin/python3
aList = [123, 'Google', 'xiaoBai', 'Taobao', 123];
print ("123 元素个数 : ", aList.count(123))
print ("xiaoBai 元素个数 : ", aList.count('xiaoBai'))
以上实例输出结果如下:
示例
123 元素个数 : 2
xiaoBai 元素个数 : 1