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

Python List count() method

Python List count() method

Python Lists Python Lists


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:



#!/usr/bin/python



aList = [123, 'xyz', 'zara', 'abc', 123];



print "Count for 123 : ", aList.count(123);

print "Count for zara : ", aList.count('zara');

The output of the above example is:



Count for 123 :  2

Count for zara :  1

Python Lists Python Lists