Strip () function in Python, strip function in python

Source: Internet
Author: User

Strip () function in Python, strip function in python

In the python API, describe the strip () function as follows:

Declaration: "s" is a string and "rm" is the sequence of characters to be deleted.

S. strip (rm) Delete the characters starting and ending in the s string and located in the rm Delete Sequence

S. lstrip (rm) Delete the characters starting from the s string in the rm Delete Sequence

S. rstrip (rm) deletes the characters at the end of the s string in the rm deletion sequence.

Note:

1. When rm is blank, blank spaces (including '\ n',' \ R', '\ t', '') are deleted by default ','')

For example:

>>> A = 'Hello world' >>> a 'hello world' >>>. strip () 'Hello world' >>> x = '\ t \ r \ npython' >>> x' \ t \ r \ npython' >>> x. strip () 'python'

2. The rm Delete sequence is deleted as long as the characters on the edge (beginning or end) are in the delete sequence.

For example:

>>> AString = '123love' >>> aString '123love' >>> aString. strip ('12') '3love'

 

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.