10 of 151 menu

The count method

The count method returns the number of matches of an element in the list. In the method parameter, we pass the element we want to find.

Syntax

list.count(what are we looking for)

Example

Let's find out how many times a string appears in our list:

lst = ['a', 'b', 'c', 'd', 'e'] print(lst.count('a'))

Result of code execution:

2

Example

Now let's find the missing element in the list:

lst = ['a', 'b', 'c', 'd', 'e'] print(lst.count('x'))

Result of code execution:

0

See also

  • method index,
    which searches for an element in a list and returns its index
  • method pop,
    which removes an element by its index
English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline