s = 'hello,world' s.capitalize() s.center(50,'*') s.count( ' h ' ,0,5) #The number of occurrences of letters in the range s.endswith( ' d ' ) s.expandtabs( 20) #Expand the tab key, the parameter is the length s.find( ' h ' ,0,5) #Find a value in the range, if not, return -1 s3 = ' my name is {0},i am {1} years old ' print(s3.format('xiang',12)) #my name is xiang,i am 12 years old s3 = 'my name is {name},i am {age} years old' print(s3.format(name = 'xiang',age = 12)) # my name is xiang,i am 12 years old s.index( ' h ' ,0,5) #find the index value s.isalnum() #letters and numbers without special symbols s.isalpha () #letters s.isdecimal () #Numbers , can not bring. s.isnumeric() #Only numbers are the same as the upper and lower two s.isdigit() #Is it an integer, the same as isdecimal s.isidentifier() #Is it an available variable name s. islower() #all lowercase s.isprintable() #can be printed s.isspace () #whether there are spaces s.istitle() #all words start with uppercase s1 = [ ' xiang ','is','35'] print(' '.join(s1)) print('-'.join(s1)) print('*'.join(s1)) s.lower() s.upper() s.strip() #Remove spaces and newlines rstrip The difference between left and right lstrip # -----maketrans\translate s1 = ' abcdefg ' s2 = '!@#$%^&*' table = str.maketrans(s1,s2) print(table) s3 = ' able to df ' print (s3.translate(table)) # ------------------------- s = ' hello world ' s. replace( ' h ' , ' - ' ,1) #Replace h with -, only replace 1 print (s) print (s.split( ' w ' )) # Cut according to what content # -----Split by line s = ' a\nb\nc\n ' print (s.splitlines()) #------------------- s.swapcase() #lowercase to uppercase s.title() #change to title format (the first letter is capitalized) s.zfill( 40) #fill with 0 to 40 lengths ''' Commonly used methods isdigit replace find count strip center split format join '''