Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python3 List count() Method

Python3 List count() Method

Python3 Lists The Python3 list


Description

The count() method counts how many times an element appears in a list.

Syntax

count() method syntax:


list.count(obj)

Parameters

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

]

;

print

(

"Number of 123 elements: "

,

aList.

count

(

123

)

)

print

(

"Number of Runoob elements: "

,

aList.

count

(

'Runoob'

)

)

The output of the above example is:


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

Python3 Lists The Python3 list