Capitalize first letter
" Alex " = test.capitalize ()print(v)
All lowercase, the first is a lot better, many unknown correspondence can be changed to lowercase
Test/casefold ()
Test.lower ()
Set the width, and put the text in the middle, 20, for total length, and X for blank padding
" ALEX " =test.center ("x")print(v)
Calculates the number of elements in the current text count,a represents the found element, 5, 6 for the beginning and end
" Alexaler " =test.count ("a", 5,6)print(v)
Whether to end with what Shartwith start with what
" Alexaler " =test.endswith ("a")print(v)
Find a character in the string position, get the first position, regardless, 5,8 indicates from where to, to find must be greater than the location, can not find the same -1,index function, but can not find an error
" Alexaler " =test.find ("R", 5,8)print(v)
formatting, replacing placeholders in strings with established values
test = al{ex}al{ex} "
#括号可替换为0,
#下面则不用ex =, write directly rprint (test) v =test.format (ex=" r " ) print (v)
" Al{0}al{1} " # brackets can be replaced by 0,1,2 # The following is not ex=, write directly R Print =test.format ("R","D") Print(v)
Determines whether the string contains only letters and numbers
" uasf890+ " = test.isalnum ()print(v)
Magic Day10 for Python strings