Python Foundation--string

Source: Internet
Author: User

string = ' Kzx truthk '
String.capitalize () # Initial uppercase String.casefold () # Uppercase All lowercase string.center ("-") # output '-------------------- -KZX truthk----------------------' string.count (' Lex ') # Statistics on the number of Lex occurrences String.encode () # Encode the string into the bytes format string.endswith ("Li") # to determine if the string ends with Li "KZX\TTRUTHK". Expandtabs () # output ' Alex Li ', will \ T convert to a long space String.find (' R ') # Find A, Find returns its index, cannot find return-1 ' 9 '. IsDigit () # whether the integer string.isnumeric () string.isprintable ( ) String.isspace () String.istitle () string.isupper () "|". Join ([' kzx ', ' truth ', ' Ke ']) # result ' kzx|truth|ke ' msg = ' My name is ' {} ' and ' age ' {} ' Print (Msg.format ("Kzx", ' xx ')
Result: My name is KZX, and an age is XX
MG = "My name is {name}," and "Age was {age}" print (Mg.format (name= ' TRUTHK ', age= "xx") Result: My name is TRUTHK, and the IS XXMG.I Ndex (' n ')  # Returns the index of the string where R is located mg.partition (' is ')  # with ' is ' partition mg  result (' My name ', ' is ', ' {name} ' and ' age ' {age} ')

A brief introduction to the Python3 string manipulation of the weak slag

If there is no, but also hope that you more advice

Python Foundation--string

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.