Python daily delicious (6)-strip lstrip rstrip

Source: Internet
Author: User
Strip in python is used to remove the first character of a string. Similarly, lstrip is used to remove the character on the left, and rstrip is used to remove the character on the right. All three functions can be passed in a parameter, specifying the first and last characters to be removed. Note that an array of characters is passed in. the compiler removes all corresponding characters at both ends until no matching characters exist, for example:

Thestring =   ' Saaaay Yes No yaaaass '
Print Thestring. Strip ( ' Say ' )

ThestringRemove characters from the ['s ', 'A', 'y'] array until the characters are not in the array.Therefore, the output result is:
Yes No
The principle of lstrip is the same as that of rstrip. Note: When no parameters are input, spaces at the beginning and end are removed by default.

Thestring =   ' Saaaay Yes No yaaaass '
Print Thestring. Strip ( ' Say ' )
Print Thestring. Strip ( ' Say ' ) # There is a space behind say
Print Thestring. lstrip ( ' Say ' )
Print Thestring. rstrip ( ' Say ' )

Running result: Yes No
Es no
Yes No yaaaass
Saaaay Yes No
Python daily delicious series (total)

Python daily delicious (4)-isinstance determines the object type

Python daily delicious (5)-ljust just Center

Python daily delicious (6)-strip lstrip rstrip

Python daily delicious (7)-join string (join %)

Python daily delicious (8)-character inversion in strings

..

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.