# 1. Find methods can be found in a long string of substrings, he returned to the sub-index of the leftmost location of the string, it returns -1 if not found
A = 'ABCDEFGHIJK'
Print (a.find ( 'ABC' )) the #The the Result : 0
Print (a.find ( 'abc' , 10, 100)) the #The the Result : 11 specified search to find the start and end position
. # 2 join method is a very important method of strings, he is split inverse methods are used to connect elements of a sequence of elements are required and must be connected to the string.
= A [ '. 1' , '2' , '. 3' ]
Print ( '+' .join (A)) the #The Result : +. 1 + 2. 3
. #. 3 Split method,
( '. 1 + 2 + +. 4. 3' .split ( '+' )) the #The Result : [ '. 1', '2', '. 3', '. 4']
. #. 4 Strip method returns to remove the first space (not including inside) string
Print ( "Test Test" .strip ()) the #The Result "Test Test":
obtained after # 5 replace string method returns a string that all matches are replaced.
Print ( "This iS a Test " .replace ( 'IS' , 'is_test' )) the #The Result : Test A This_test is_test
1.2 common method string
Guess you like
Origin www.cnblogs.com/lihouqi/p/12664227.html
Ranking