Str
Slice Str[start:end] Note: Gu Tou regardless of tail
STR[M:N:S] s for step
Case Conversion Ret1 = S1.capitalize () Capitalize first letter ret = S1.lower () convert all to write
ret = S1.upper () convert all to write
ret = S1.swapcase ()?? Write to convert each other
ret = S1.casefold () convert all to write
ret = S3.title () Each word separated by a special character?? Word?? Write
Various cutting
ret = S5.center (10, "*") pull into 10, put the original string in the middle. The rest of the position
S6.expandtabs () can change \ t's degree, default? degree changed to 8
ret = S7.strip () remove left and right spaces
ret = S7.lstrip () Remove left space
ret = S7.rstrip () Remove the right space
S7.strip ("ABC") can also specify which elements are removed
Replace
ret = S8.replace (' Alex ', '??? King ') to replace Alex with??? Wang
ret = s8.replace (' i ', ' SB ', 2) Replace I to SB, replace 2
9 = "Alex,wusir,sylar,taibai,eggon"
LST = S9.split (",") string cut, according to, in-cut
Format and output
S12 = "My name is%s, this year%d years old, I like%s"% (' Sylar ', 18, ' Jay Chou ')
Find
Ret1 = S13.startswith ("Sylar") determines whether to start with Sylar
Ret3 = S13.endswith ("Language?") Is it a ' language? ' End
Ret7 = S13.count ("a") find the number of occurrences of "a"
Ret5 = S13.find ("Sylar") find where ' Sylar ' appears
Ret7 = S13.find ("A", 8, 22) cut to find
Ret8 = S13.index ("Sylar") Quest position. Attention. If the index is not found. Program will error
Conditional judgment
is print (S14.isalnum ()) made up of words and numbers?
is print (S14.isalpha ()) composed of words?
Print (S14.isdigit ()) whether the number consists of
ret = Len (S18) calculates the degree of a string
List
python int str bool List dict Data operation method Summary