Usage of "Python" strip ()

Source: Internet
Author: User

I saw it today.

Http://www.pythondoc.com/pythontutorial27/datastructures.html#tut-tuples

5.1.4, there is a paragraph:

?
123 >>> freshfruit =[‘  banana‘‘  loganberry ‘‘passion fruit  ‘]>>> [weapon.strip() for weapon infreshfruit][‘banana‘‘loganberry‘‘passion fruit‘]

Think of the use of strip ().

The following excerpt from http://www.cnblogs.com/kaituorensheng/archive/2013/05/23/3096028.html

Function prototypes

declaration : S is a string, RM is a sequence of characters to be deleted

S.strip (RM) Remove the characters from the beginning and end of the s string in the RM delete sequence

S.lstrip (RM) Delete the character in the S string at the beginning of the RM delete sequence

S.rstrip (RM) Removes the character from the end of the S string that is located in the RM delete sequence

Note :

1. When RM is empty, the default is to remove the whitespace characters (including ' \ n ', ' \ R ', ' \ t ', ')

For example:

2. The RM delete sequence here is deleted as long as the character on the edge (beginning or end) is within the delete sequence.

For example:

1 ' 123ABC ' 2 a.strip ('+ ')3 >>>'3abc ' 4 A.strip ('5 ') >>>'  3ABC'

The result is the same.

More Intuitive: RM content, as long as at both ends, will be caught out, but if you encounter a character that is not in RM, it will stop to the middle of the search (the search will not stop, you can always go to the left or to the right).

Examples are as follows:

?
1234567 >>> b =‘211111‘>>> b.strip(‘1‘)‘2‘ >>> a =‘1234516‘>>> a.strip(‘12‘)‘34516‘

The first paragraph demonstrates the constant retrieval and removal of characters, and the second paragraph demonstrates stopping the search.

The returned value did not remove the second-to-last 1, the left 1 is removed, and the second character 2 is also removed from the RM.

The ' 6 ' on the right is like a wall that protects the second-to-last ' 1 '.

Well, I also know it's a very simple thing. HHH, write down consolation, this is the first, I hope not the last article,

Hello world!

Usage of "Python" strip ()

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.