Python String manipulation functions

Source: Internet
Author: User

#-*-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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.