What is the syntax to count how many times a value is contained in a string?

<string name>.count(<sub>, <start>, <end>)
#sub - value to be searched for within <string name>
#start - start index of search, inclusive
#end - end index of search, exclusive
#example
str = 'HELLO WORLD'
print(str.count("L",0))
print(str.count("D",0,10))
print(str.count("L",1,3))

#output
3
0
1

 

Advertisements