Python data Type---string

Source: Internet
Author: User

1. String to remove whitespace, strip (), including spaces, tab, line break

"   Frank  ">>> name.strip ()'Frank'

2. Splitting of the string, split ("delimiter"), grouped into a list

" Apple, Banbana, Orice ">>> name.split (",") ['Apple' ' Banbana ' ' Orice ' ]>>>

3. Merge Join for string ("connector")

>>> name = ['Frank''Marlon'Lee ' ]"| " . Join (name) ' frank| marlon| Lee'

4. Determine if the space is a substring of "in"

" Frank Bain " "' inch nametrue " L " inch Namefalse>>>

5. Two kinds of string format print formats format

#The first method of presentation>>> msg ="Hello {Name}, your age was {age}">>> Msg.format (name="Frank", age=24)'Hello Frank, your'>>>#the second method of presentation, note that index starts from 0>>> msg ="hello{0}, your age was {1}, sex is {2}">>> Msg.format ("Frank", 24,"Mans")'Hellofrank, your age was, sex is man'>>>

6. The judgment of the string

>>> name ="Frank">>>Name.upper ()'FRANK'>>>Name.lower ()'Frank'>>> Name.startswith ("F") True>>> Name.endswith ("k") True>>> Name.endswith ("a") False

Python data Type---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.