This article introduces the use of the count () method of Python string processing, which is the basics of getting started in Python, and needs friends to refer to the
The count () method returns the string number range [Start, end] that appears in the range. The start and end of an optional parameter are interpreted as a slice symbol.
The following is the syntax for the Count () method:
|1||Str.count (Sub, start= 0,end=len (String))|
Sub-This is a substring used for searching.
Start--Search from this index. Index of the first character starting from 0. Searches for indexes starting with 0 by default.
End--The search ends from the index. Index of the first character starting from 0. The last index that the search ends by default.
This method returns a string centered on the length width.
The following example shows the use of the count () method.
|1 2 3 4 5 6 7 8||#!/usr/bin/python str = "This is string Example....wow!!!"; Sub = "I"; Print "Str.count (sub, 4,):", Str.count (Sub, 4,) sub = "Wow"; Print "Str.count (sub):", Str.count (sub)|
When we run the above program, it produces the following results:
|1 2||Str.count (Sub, 4,): 2 Str.count (Sub, 4, 40): 1|