python string Common methods
password='. jpg 123456789. jpg abcdfg\n' #the value of the string cannot be changed##strip () methodPrint(Password.strip ())#by default, whitespace and line breaks are removed on both sides of the stringPrint(Password.strip ('. jpg'))#remove the. jpg from both sidesPrint(Password.lstrip ())#drop the left space and line break of the stringPrint(Password.rstrip ())#Drop the space and line breaks to the right of the string##大小写转换Print(Password.upper ())#turn into uppercasePrint(Password.lower ())#turn into lowercasePrint(Password.capitalize ())#first letter to uppercase##替换Print(Password.replace ('123','hehe'))#ReplacePrint(Password.replace (' ',"'))#Remove all spaces in a string## start, EndFilename='A.mp3'Print(Filename.endswith ('. mp3'))#decide whether to end with XXPrint(Filename.startswith ('186'))#decide whether to start with XX##字符串分割, switch to listnames='morning Greek, Rui Han, raisin, library'Print(Names.split ())#the string into a list, if you do not specify what to split, the default is separated by a space;Print(Names.split ('.'))#If the delimiter does not exist, place the entire string as an element in the listPrint(Names.split (','))#1. Change the string to List 2, split it with an element, and divide it into a list of each element .Print(list (names))
Python (4)---string common methods