Learning Python language, I had to learn Python, string processing,
We can see in the str class provides many methods of operation of the string, we now need to do is to frequently used
In this method were summarized and learning. See in particular the following code:
# ! / Usr / bin / Python the env # UTF-. 8: Coding STR = ' the Hello ' # first letter capitalized variant Print str.capitalize () # SUMMARY centrally Print str.center (30, ' = ' ) # a subsequence number (letters appear several times in the string) Print str.count ( ' L ' ) # whether any end Print str.endswith ( ' O ' ) # whether what started Print str.startswith ( ' H ' ) # processing tab key str2 =' The Hello \ T999 ' Print str2.expandtabs () # Looking sequence position -1 is not found, is returned. 1 Print str.find ( ' A ' ) # find the location of the sub-sequence is not found on the error Print STR. index ( ' E ' ) # formatted output string, which is the placeholder Age = 20 is name = ' Hello ' Print ' name iS {0}, and {. 1 Age iS} ' .format (name, Age) # determining whether the letters and numbers Print str.isalnum () # determines whether letters Print str.isalpha () # determines whether the digital Print str.isdigit () # to determine whether lowercase Print str.islower () # determine whether there is a space Print str.isspace () # determine whether it is capitalized Print str.isupper () # determine whether it is heading -> first letter capitalized, It will be appreciated uppercase Print str.istitle () # .join connection strings S1 = [ ' appium ' , ' Selenium ' , ' Android ' , ' iOS ' ] Print ' *** ' .join (S1) # use .join () into the list of strings Print ' ,' .Join (S1) # string to the list of A = ' ABC ' Print a.split ( ' ' ) # remove Blank S3 = ' Hello ' Print s3.strip () # remove the left space S4 = ' Hello ' Print s4.lstrip () # remove the right box S5 = ' World ' Print s5.rstrip () # string lowercase the Print str.lower () # split string, a tuple after division is S = ' wuya Python iS ' prints.partition ( ' IS ' ) # replacement string Print s.replace does ( ' wuya ' , ' Selenium ' ) # rfind () from right to left looking Print s.rfind ( ' wuya ' ) # bytes string can turn into byte str5 = ' Hello ' Print bytes (str5)