#-*-coding:utf-8-*-Strword="I'll fly with you and fly on the sky."#FindPrint(Strword.find ("Fly"))#Printing 7#Find returns a subscript that finds the first string, and cannot find the return-1Print("==rfind==")#RFindPrint(Strword.rfind ("Fly"))#RFind from the back forward to find the return subscript, can not find the return-1Print("==index==")#IndexPrint(Strword.index ("Fly")) #Index found the subscript to return the first character, unable to find an error valueerror:substring not foundPrint("==rindex==")#RindexPrint(Strword.rindex ("Fly"))#functions similar to RFind, with different return valuesPrint("==count==")#CountPrint(Strword.count ("Fly"))#Count returns the number of found strings, not found return 0Print("==replace==")#ReplacePrint(Strword.replace ("Fly","XXX"))#full text replaces the specified string, and the replace () function does not modify the value of Strword because the string is of an immutable type#The Replace extension can specify how many to replace, but the order of substitution is still the previous backwardPrint(Strword.replace ("Fly","XXX", 1))Print("===split==")#SplitPrint(Strword.split (" "))#split cut function, cut string by specified characterWord="Hello World"Print("==capitalize==")#CapitalizePrint(Word.capitalize ())#capitalize the first character of the first word of a stringPrint("==title==")Print(Word.title ())#capitalize the first letter of each word in the title stringPrint("==startswith==")Print(Word.startswith ("He"))#StartsWith whether to start with a string, is to return true, not to return flasePrint("==endswith==")Print(Word.endswith ("LD"))#EndsWith to the end of a string, is to return true, not to return flaseNword="a b c a B c"Print("==lower==")Print(Nword.lower ())#Lower convert all English characters to lowercasePrint("==upper==")#UpperPrint(Nword.upper ())#Upper Convert all English characters to uppercase
Python String manipulation functions