Python count () method
description
Python count () method is used in a number of statistical string of characters appears. Optional parameters at the beginning and end of the string search.
count () method syntax:
str.count(sub, start= 0,end=len(string))
parameter
sub - substring search
start - the string to start the search. The default is the first character, the first character index value of zero.
end - the end of the search string position. Character index of the first character is 0. The default is the last position of the string.
return value
The method returns the number of substrings in the string appears.
The following example shows an example of count () method:
Example (Python 2.0+)
#!/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)
Examples of the above output results are as follows:
str.count(sub, 4, 40) : 2 str.count(sub) : 1