Python string operation, python string

Source: Internet
Author: User

Python string operation, python string

Hard to remember

Name = "abcde"

Name2 = abcd \ te

Name. capitalize () // uppercase letters

Name. count ("a") // count the number of

Name. casefold ()

Name. center (10, "-") // output: --------- abcde ---------

Name. encode () // convert to binary

Name. endswith ("e") // determines whether a string ends with e.

Name2.expandtabs (tabsize = 10) // output: abcd e

Name. find ("a") // returns the index of the character found.

Name. format () // format the string

Name. format_map ({"name": "aa", "age": 12 })

Name. isalnum () // determines whether it is an Arabic number. If the character contains a number, true is returned.

Name. isalpha () // determines whether it is a pure English character

Name. isdigit () // determines whether it is an integer.

Name. isdentifier () // identifies a valid identifier (variable name)

Name. islower () // determines whether it is in lowercase.

Name. isspance () // determines whether it is a space.

Name. istitle () // whether the title Is My Name Is an uppercase letter. true Is returned.

Name. isprinttable () // determines whether printing is allowed

Name. isupper () // whether to use uppercase letters

Name. join ("=") // output: = abcde =

",". Join (['1', '2', '3']) // output 1, 2, 3

Name. ljust (50, "*") // output abcde ********* length is not enough 50 left side with * fill

Name. Must ust (50, '*') Same as above to the right

Name. lower () lower case

Name. upper () Capital

Name. lstrip () // remove spaces and line breaks on the left

Name. rstrip () Same as above on the right

Name. strip () // both sides

Name = str. maketrans ("abc", "123 ")

"Abcfer". translate (name) // output: 123fer

Name. replace ("a", "m", 1) // replace a with m to replace only one

Name. rfind ("e") Find the rightmost e return subscript

Name. split ('B') // splits the string into List B by default, which will be removed during split.

Name. splitlines ()

Name. swapcase () // converts uppercase letters to lowercase letters to uppercase letters.

Name. zfill (50) // If the length is not enough, auto-fill the value on the left

 

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.