Python3 List count() Method

Python3 列表Python3 Lists


Description

The count() method is used to count the number of times an element appears in a list.

Syntax

count() method syntax:

list.count(obj)

Parameters

  • obj -- The object to be counted in the list.

Return Value

Returns the number of times the element appears in the list.

Example

The following example demonstrates how to use the count() function:

Example

#!/usr/bin/python3

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

print ("123 element count : ", aList.count(123))
print ("Example element count : ", aList.count('Example'))

The output of the above example is as follows:

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

Python3 列表Python3 Lists

Other Extensions