Look like dividing Python string interception

Taken Python string using the variable [the header: Tail index], which could be intercepted corresponding string, where the subscript 0 is counted from the beginning, can be positive or negative, the subscript can represent an empty take head or tail .

= str ' 12345678 ' 
Print str [0: 1] # output str start position 0 to position 1 of the previous character 
>> 1

Replacement string using the variable .replace Python ( "replaced content," "content after the replacement," [the number]), the number of replacement may be empty, it means that all the replacement. Note that the use of replace replacement string is only temporary variables need to be reassigned to save.

str = str.replace('k',' 8')

Python using the search string variable .find ( "what to look for," [, start position, end position]), the start position and end position, represents the range're looking for, it means to find all empty. After finding the position will return to the position began to count from 0, if each found -1 is returned.

str.find('hello')

Python string using the variable .split divided ( "split symbol labeled" [division number]), the number of divisions indicates the maximum number of segmentation, segmentation is empty all.

str='1,2'
strlist = str.split(',')
print strlist[1]
>>2

 

Guess you like

Origin www.cnblogs.com/xxxuxin/p/10932728.html