#-*-coding:utf-8-*-name="Wangcai"#Capitalize first letterPrint(Name.capitalize ())#number of occurrences of a statisticPrint(Name.count ("a"))#Print 50 characters, not enough-upPrint(Name.center (50,"-"))#Print 20 characters, less than 20 are added in the rear *Print(Name.ljust (20,"*"))#Print 20 characters, less than 20 add in front of *Print(Name.rjust (20,"*"))#determines whether the string ends with the specified stringPrint(Name.endswith ("Cai"))#determines whether a file starts with a specified stringPrint(Name.startswith ("Cai"))#gets the subscript of the specified stringPrint(Name.find ("C"))#looking forward from behindPrint(Name.rfind ("W"))#formatted outputstr ="My name is {name}, and age was {age}"#format, which is the output of my name is Wangwang, which isPrint(Str.format (name='Wangwang', age=23))#Format_map, referring to a map as a parameter, the output is the My name is Wangcai, which isPrint(Str.format_map ({"name":"Wangcai"," Age": 22}))#The judgment is not to contain only the English characters and the sum of the words "Aa12" fruit to True, "Aa12," to falseLAN ="Aa12" Print(Lan.isalnum ())#To judge whether it contains only English charactersPrint(Lan.isalpha ())#Judging is not an integernum =" About"Print(Num.isdigit ())#The judgment is not a valid identifier (is not a valid variable name)Print(Num.isidentifier ())#Judging is not all lowercasePrint(Name.islower ())#Judging is not uppercasePrint(Name.isupper ())#determine if each initial letter is capitalizedPrint(Name.istitle ())#adds a string result between the two elements of a list a+b+cPrint('+'. Join (["a","b","C"]))#turn uppercase to lowercasePrint(Lan.lower ())#turn lowercase to uppercasePrint(Name.upper ())#Removing line breaks and carriage returnsPrint("a". Strip ())#remove the left line break and enterPrint("a". Lstrip ())#Remove the right line break and enterPrint("a". Rstrip ())#Replace , replace a with a with a, and the number behind indicates the substitution of a fewPrint(Name.replace ("a","A", 1))#split the string to generate a listPrint(Name.split ("a"))#capitalize a string to lowercase, lowercase to uppercasePrint('AaBB'. Swapcase ())#turn the initial letter into uppercasePrint("AA BB Cc". Title ())
Python string processing