String method
find join lower replace split strip translate
Find
You can find the string in a longer string, the return value is the leftmost index of the location where the string is located, and cannot find the return-1
Cases:
>>> ' with a Moo-moo here,and a moo-moo there '. Find (' moo ')
7
>>> ' with a Moo-moo here,and a moo-moo there '. Find (' Hello ')
-1
Join
The element in the connecting sequence is the inverse method of Split
Cases:
>>>sss = [' 1 ', ' 2 ', ' 3 '] #注意: This must be quoted, because it can only concatenate strings
>>>CCC = ' + '
>>>ccc.join (SSS)
' 1+2+3 '
>>>dirs = ', ' usr ', ' bin ', ' env '
>>> '/'. Join (dirs)
'/usr/bin/env '
>>> print ' C: ' + ' \ \ '. Join (dirs)
C:\usr\bin\env
Lower
Returns the lowercase letter version of the character
Cases:
>>> ' Where is You '. Lower ()
' Where is You '
Replace
The resulting string after all occurrences of a string have been replaced
Cases:
>>> ' This was a test '. Replace (' is ', ' EEZ ')
' Theez eez a test '
Split
Splitting a string into a sequence , the inverse method of the Join method
Cases:
>>> ' 1+2+3+4 '. Split (' + ') #此处若不指定任何分割符 with a space separator (space, tab, line wrap, etc.)
[' 1 ', ' 2 ', ' 3 ', ' 4 ']
Strip
Returns a string that strips both sides of the space (excluding interior)
Cases:
>>> ' where is You '. Strip ()
' Where is You '
>>> ' ***where * is * you *********! '. Strip (*!)
' WHERE * is * you '
Translate
Replace Some parts of a string, handling only a single character
This article is from the "Ride a Pig to Travel" blog, please be sure to keep this source http://songqinglong.blog.51cto.com/7591177/1712599
Python Learning notes (10)