Python string method summary

 

Features Description Method name/portal
Concatenated string Concatenate the sequence into a complete string. join
Split string Split a character string according to the specified characters. split
Type judgment Determine whether a string is all numeric strings. isdigit
Determine whether a string is all uppercase and lowercase letters. isalpha
Determine whether a string is all numeric or uppercase and lowercase letters. isalnum
String count Count the number of occurrences of the specified character string in the source character string. count
Remove the string at the beginning and end Remove the specified string at both ends of the string. strip
Typesetting method Center the string content. center
Align the content of the string to the left. light
Align the string content to the right. rjust
Uppercase and lowercase letters conversion Swap uppercase and lowercase letters in the string. swapcase
Convert uppercase letters to lowercase letters. lower
Convert lowercase letters to uppercase letters. upper
Capitalize the first letter Capitalize the first letter of the string. capitalize
Capitalize the first letter of each word in the string. title
Find string Find the last occurrence of a string in another string. rfind
Find the first occurrence of a string in another string. find
Detect the beginning of a string Check whether the string starts with the specified string. startswith
Detect end of string Check whether the string ends with the specified string. endswith
String replacement Replace all or part of the string. replace

 

Guess you like

Origin blog.csdn.net/TCatTime/article/details/111170934