1 find (), RFind (), index (), Rindex (), COUNT ()
s ="This apple is red apple"S.find ("Apple") S.find ("Apple", 9) S.find ("Apple", 1,3) S.rfind ("app")#looking forward from the end of a stringS.index ("pp") S.count ("P")
2 split (), Rsplit (), partition (), Rpartition ()
Partition divides the string into three parts, before the delimiter, the delimiter, and the ' R ' represents the forward from the tail
S.split ('# ' uses spaces to split [' This ', ' apple ', ' is ', ' red ', ' apple ']s.partition (' ') # (' This ', ' ", ' Apple is Red apple ')
3 Join ()
Multiple string connections, adjacent strings inserted into specified characters
S1 = s.split (""-"#" This-apple-is-red-apple '
4 lower (), upper (), capitalize (), title (), Swapcase ()
Converts a string to lowercase, uppercase, first uppercase, uppercase for each word, case-by-letter
5 replace ()
S.replace ("Apple","Orange"#' This orange is red Orang '
6 Maketrans (), translate ()
Maketrans () generates a character map, translate () replaces characters by mapping table, and the second parameter is the character to be deleted
Importstringtable= String.maketrans ("ABCDEFG","1234567") s="This apple is red apple"s.translate (table)#' This 1ppl5 is r54 1ppl5 'S.translate (table,"Hijk")#remove Hijk ' ts 1ppl5 s r54 1ppl5 '
7 strip (), Rstrip (), Lstrip ()
Remove both ends, right, left whitespace characters, or specified characters
s ="ABC"S.strip ()#remove both whitespace characters ' abc '"ABDC". Strip ("a")#Delete the specified character"aabdcaaa". Rstrip ("a")#Delete the right end of the specified character ' AABDC '
8 eval ()
Attempt to convert any character to an expression for evaluation
Eval ("3+4")import matheval ('math.sqrt (3) ')
9 StartsWith (), EndsWith ()
Determines whether a string starts or ends with a specified string
Isalnum (), Isalpha (), IsDigit (), Isspace (), Isupper (), Islower ()
Tests whether a string is a number or letter, whether it is a letter, whether it is a number, whether it is blank, uppercase, lowercase
Python base 5--string