Features: cannot be modified
Name.capitalize () initial capital Name.casefold () uppercase all lowercase name.center ("-") output '---------------------alex li----------------------' name.count (' Lex ') statistics Lex occurrences Name.encode () encodes a string into bytes format name.endswith ("Li") determines whether the string ends with li "Alex\tli ". Expandtabs () output ' alex li ', convert \ t to how long the space name.find (' A ') find A, find returns its index, not found return -1 format : >>> msg = "my name is {}, and age is {}" >>> msg.format ("Alex") ' My name is alex, and age is 22 ' >>> msg = ' My name is {1}, and age is {0} " >>> msg.format (" Alex ") ' MY NAME IS 22,&NBsp;and age is alex ' >>> msg = ' my name is {name}, and age is {age} " >>> Msg.format (age=22,name= "ale") ' My name is ale, and age is 22 ' Format_map >>> msg.format_map ({' name ': ' Alex ', ' age ': ') ' ' my name is alex, and age is 22 ' Msg.index (' a ') Returns the index ' 9aA ' of the string where a is located. isalnum () true ' 9 '. IsDigit () integer name.isnumeric name.isprintablename.isspacename.istitlename.isupper "|". Join ([' Alex ', ' Jack ', ' Rain ']) ' Alex|jack|rain ' maketrans >>> intab = "Aeiou" #This is the string having actual characters. >>> outtab = "12345" #This is The string having corresponding mapping character >>> trantab = str.maketrans (Intab, outtab) >>> >>> str = "This is string example....wow!!!" >>> str.translate (trantab) ' th3s 3s STR3NG 2X1MPL2....W4W!!! ' msg.partition (' is ') output (' my name ', ' is ', ' {name}, And age is {age} ') >>> "Alex li, chinese name is lijie ". Replace (" Li "," Li ", 1) ' Alex li, chinese name is lijie ' msg.swapcase case >>> msg.zfill (+) ' 00000my name is {name}, and age is {age} ' >>> n4.ljust (+, "-") ' Hello 2orld-----------------------------' >>> n4.rjust (+, "-") '-----------------------------Hello 2orld ' >>> b= "ddefdsdff_ haha" >>> b.isidentifier () #检测一段字符串可否被当作标志符, that is, whether to conform to the variable naming rules true
This article is from the "Little Rookie" blog, please be sure to keep this source http://baishuchao.blog.51cto.com/12918589/1935005
Python string manipulation