Python3 List count() Method
Description
The count() method counts how many times an element appears in a list.
Syntax
count() method syntax:
list.count(obj)
Parameters
- obj -- the object to count in the list.
Return Value
Returns the number of times the element appears in the list.
Example
The following example shows how to use the count() function:
Example
#!/usr/bin/python3
aList
=
[
123
,
'Google'
,
'Runoob'
,
'Taobao'
,
123
]
;
(
"Number of 123 elements: "
,
aList.
count
(
123
)
)
(
"Number of Runoob elements: "
,
aList.
count
(
'Runoob'
)
)
The output of the above example is:
123 元素个数 : 2
Runoob 元素个数 : 1
The Python3 list