The strip of Python functions () __ function

Source: Internet
Author: User

The strip in Python is used to remove the first (left) character of a string, and Lstrip is used to remove the left character, Rstrip to remove the right character. All three functions can pass in one parameter, specifying the first and last characters to be removed.

s= ' Saaaay Yes no Yaaaas '
print s.strip (' say ') #结果是 '   Yes   no  '

Explanation: The incoming is an array of characters, the compiler removes all the corresponding characters at both ends until there are no matching characters. The array of characters passed in is [' s ', ' a ', ' Y '], from the sides of the string s, if any character in the character array is encountered (in character order), the character is deleted, otherwise the operation stops.
If the strip () does not pass the parameter, the default deletion of whitespace characters (including ' \ n ', ' \ R ', ' \ t ', ')

Several instances are given below

>>> s= '    saaay  yes no Yaaaas  '
>>> s.strip (' say ')
'    saaay  Yes No Yaaaas  '
>>> s= ' ay uyes no '
>>> s.strip (' say ')
' Uyes no '

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.