python logo

python string count


Python hosting: Host, run, and code Python in the cloud!

Return the number of substrings in string.

Syntax


The format is:

str.count(sub)

or
str.count(sub,start,end)


Parameters

Sub substring to count

Example

str = "The string count method returns the number of sub string occurences. "
print( str.count("string") )

Result:

2
Back





Leave a Reply: