PythonStringcount

Returns the number of non-overlapping occurrences of a substring.

Syntax

str.count(sub, start?, end?)

Example

Enter values below to update the example in real time.

print
text = "banana"
print(text.count("a"))   # 3
print(text.count("an"))  # 2