python--string

Source: Internet
Author: User

Long string

" "           ---------userinfo----------          name:lalalaxpf          age:18          sex:man          iphone:123          Address:ooxx          -----------End--------------        " " Print (str)           ---------userinfo----------          name:lalalaxpf age          :          sex:man          iphone:123           Address:ooxx          -----------End--------------

Raw string

Special meaning of the cancellation character

Print ('oo\nxx') Ooxx Print (R'oo\nxx') oo\nxx

string concatenation

1. Connect via +

Print ('oo'+'xx') Ooxx

2. Join () method

>>> list = ['a','b']'. Join ( List)'ab'

String slicing, intercepting

Grammar

Str[start:end:step]

String Common methods

Str.strip ()

# remove spaces and line breaks, not in the middle '     \noo  \nxx\n   '>>> str.strip ()'oo  \nxx '
# Remove the specified string ' Ooxx '>>> str.strip ('xx')'oo '

Str.lstrip (), Str.rstrip ()

'    Ooxx   '>>> str.lstrip ()# Remove the left space and line break 'Ooxx    '>>> str.rstrip ()# Remove the space on the right and line break '   Ooxx '

Str.count ()

# find the number of occurrences of a character in a string ' Ooxx '>>> str.count ('o')2

Str.capitalize ()

# Capitalize first letter ' Ooxx '>>> str.capitalize ()'ooxx'

Str.title ()

# all words start with uppercase, and the remaining letters are lowercase ' Hello World '>>> str.title ()'HelloWorld'

python--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.