count() Method is used to count the number of occurrences of a character or substring in a string
Optional parameters are at the beginning and end of string search
grammar
str.count(sub, start=0,end=len(string))
Parameters
sub : The search of Substring
start : Where the string starts searching
The default is the first character , The first character index value is 0
end : Where to end the search in the string
The index of the first character in the character is 0, Default to the last position of the string
Return value
This method returns the number of times the substring appears in the string
str = "this is string example....wow!!!"
sub1 = "i"
# str.count(sub1, 4, 40): 2
print("str.count(sub1, 4, 40):", str.count(sub1, 4, 40))
# str.count(sub): 1
sub2 = "wow"
print("str.count(sub2):", str.count(sub))
Python count() Method | Novice tutorial