Python3 List count()方法

Python 3 教程 · 2019-02-06 12:26:49

描述

count() 方法用于统计某个元素在列表中出现的次数。

语法

count()方法语法:

list.count(obj)

参数

  • obj -- 列表中统计的对象。

返回值

返回元素在列表中出现的次数。

实例

以下实例展示了 count()函数的使用方法:

#!/usr/bin/python3

aList = [123, 'Google', 'Codercto', 'Taobao', 123];

print ("123 元素个数 : ", aList.count(123))
print ("Codercto 元素个数 : ", aList.count('Codercto'))

以上实例输出结果如下:

123 元素个数 :  2
Codercto 元素个数 :  1

点击查看所有 Python 3 教程 文章: https://codercto.com/courses/l/10.html

查看所有标签

Haskell Programming from first principles

Haskell Programming from first principles

Christopher Allen、Julie Moronuki / 2015 / USD 59.00

I am writing this book because I had a hard time learning Haskell. It doesn't have to be that way. I've spent the last couple years actively teaching Haskell online and in person. Along the way, I ......一起来看看 《Haskell Programming from first principles》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

在线进制转换器
在线进制转换器

各进制数互转换器

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具