Chapters
Python114 chapters

ReferenceString methods

str.count()

How many non-overlapping times a piece of text appears.

Signature

text.count(sub)

Parameters

NameMeans
subwhat to count

Returns

An int.

Example

Python
print("one,two,one".count("one"))
print("aaaa".count("aa"))

Output

2
2

See also