Python Basics
Python Advanced
Python Useful References
Python Useful Resources
Selected Reading
© 2011 TutorialsPoint.COM
|
Python String count() Method
Description:
This method returns the number of occurrences of substring sub in the range [start, end]. Optional arguments start and end are interpreted as in slice notation.
Syntax:
str.count(str, beg= 0,end=len(string))
|
Parameters:
Here is the detail of parameters:
sub: is the substring to be searched.
start: search starts from this index. First character starts from 0 index. By default search starts from 0 index.
end: search ends from this index. First character starts from 0 index. By default search ends at the last index.
Return Value:
It returns centered in a string of length width.
Example:
#!/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)
|
This will produce following result:
str.count(sub, 4, 40) : 2
str.count(sub, 4, 40) : 1
|
|
|
|