The count() method in Python String returns the number of occurrences of substring sub in the range [start, end]. Optional arguments start and end are interpreted as in slice notation.
str.count(sub, start= 0,end=len(string))
Centered in a string of length width.
#!/usr/bin/python str = "this is string example....wow!!!"; sub = "i"; print "str.count(sub, 4, 40) : ", str.count(sub, 4, 40) sub = "wow"; print "str.count(sub) : ", str.count(sub)
str.count(sub, 4, 40) : 2 str.count(sub) : 1
Here at Intellinuts, we have created a complete Python tutorial for Beginners to get started in Python.