2017-07-03 23:26:08
1,. replace (self, old, new, count=-1)
The replace () function replaces the old string with the new string, and the last parameter, count, is optional, representing a maximum of count times (less than count).
Note that this substitution returns the replaced string, and the source string is unchanged.
s='ABCDEF'out =s.replace ('ef','EF ')print(s)printoutput: Abcdefabcdef
2. Find (self, sub, start=0, end=len)
The Find () function returns the subscript index of the first character sub, which, by default, scans the entire string, but can set the start,end itself, consistent with the STL, where the starting interval is closed before opening.
Not found, return-1
s='ABCDEF'print(s.find ('BC', 0,1)) Print(S.find ('CD')) output:12
The. RFind () function is a right-to-left search, which returns the subscript of the sub string with the largest index value, or 1 if no search is made.
3.
Python String Common functions