Python string built-in functions:
#==================== Common Methods =============================
Name ='besttest'new_name= Name.strip ()#The default is to remove both spaces and line breaksNew_name= Name.lstrip ()#The default is to remove the left space and line breakNew_name= Name.rstrip ()#The default is to remove the space and line breaks on the right sideNew_name = Name.count ('T')#find the number of occurrences of a string within a stringindex = Name.find ('D')#find the string, return its subscript, or 1 if it does not exist .index = Name.index ('D')#find this string, return its subscript, if it does not exist, errorPrint(Name.upper ())#to capitalize all the letters.Print(Name.lower ())#to turn all the letters into lowercase.file_name ='A.xls'Print(File_name.endswith ('. xls'))#determines whether a string ends in XXsql ='select * from user; Select'Sql.startswith ('Select')#determines whether a string begins with XXf ='{Name} Welcome to age: {Age}'Print(F.format (name='Caocao'))#string FormattingD = {'name':'Yuanbaoqiang',' Age': 18}Print(F.format_map (d))#string formatting, which is passed in a dictionaryNew_sql = Sql.replace ('Select','Update')#string substitution, first old,newPrint(New_sql)Print('122s'. IsDigit ())#whether it is a numberPrint('&'. Isalnum ())#Whether it contains numbers or lettersSt ='a b c D f g'st_list= St.split ()#If you don't write anything, divide it by the space.Print(st_list)#=========== Less common method ====================new_name= Name.capitalize ()#Capitalize first letterName.center (50,'*')#Put the string in the middle, both sides with *Print('AaAA'. Islower ())#whether it is a lowercase letterPrint('AAaa'. Isupper ())#whether it is a capital letterPrint('SDFSDF'. Isalpha ())#whether it is an English letter
Python Learning Note (ii)-string method