python int str bool List dict Data operation method Summary

Source: Internet
Author: User

Str

Slice Str[start:end] Note: Gu Tou regardless of tail

STR[M:N:S] s for step

Case Conversion Ret1 = S1.capitalize () Capitalize first letter ret = S1.lower () convert all to write
ret = S1.upper () convert all to write

ret = S1.swapcase ()?? Write to convert each other

ret = S1.casefold () convert all to write
ret = S3.title () Each word separated by a special character?? Word?? Write

Various cutting

ret = S5.center (10, "*") pull into 10, put the original string in the middle. The rest of the position

S6.expandtabs () can change \ t's degree, default? degree changed to 8

ret = S7.strip () remove left and right spaces

ret = S7.lstrip () Remove left space

ret = S7.rstrip () Remove the right space

S7.strip ("ABC") can also specify which elements are removed

Replace

ret = S8.replace (' Alex ', '??? King ') to replace Alex with??? Wang

ret = s8.replace (' i ', ' SB ', 2) Replace I to SB, replace 2

9 = "Alex,wusir,sylar,taibai,eggon"
LST = S9.split (",") string cut, according to, in-cut

Format and output

S12 = "My name is%s, this year%d years old, I like%s"% (' Sylar ', 18, ' Jay Chou ')

Find

Ret1 = S13.startswith ("Sylar") determines whether to start with Sylar

Ret3 = S13.endswith ("Language?") Is it a ' language? ' End

Ret7 = S13.count ("a") find the number of occurrences of "a"

Ret5 = S13.find ("Sylar") find where ' Sylar ' appears
Ret7 = S13.find ("A", 8, 22) cut to find

Ret8 = S13.index ("Sylar") Quest position. Attention. If the index is not found. Program will error

Conditional judgment

is print (S14.isalnum ()) made up of words and numbers?

is print (S14.isalpha ()) composed of words?

Print (S14.isdigit ()) whether the number consists of

ret = Len (S18) calculates the degree of a string

List

        

    

python int str bool List dict Data operation method Summary

Related Article

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.