Introduction to the strip, lstrip, and rstrip functions in python

Source: Internet
Author: User
This article mainly introduces the strip, lstrip, and rstrip functions in python. For more information, see I. cause

In role control today, rstrip is used to determine whether the url requested by the user matches the url in the available permissions of the database.

If request. path = x. url or request. path. rstrip ('/') = x. url: # exact match to determine the request. whether the path matches one of the permission tables
Take this opportunity to summarize strip, lstrip, and rstrip in python.

II. Introduction

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 parameters can be passed in a parameter that specifies the first and last characters to be removed.

Note that the input is a character array. the compiler removes all matching characters at both ends until no matching characters exist, for example:

>>> testString="saaaay yes no yaaaass">>> print testString.strip('say') yes no >>> 

It can be seen that testString is removed from the ['s ', 'A', 'y'] array until the remaining characters are no longer in the array. Therefore, yes no is output.

Note:

If no parameter is input, spaces at the beginning and end are removed by default.

The principle of lstrip is the same as that of rstrip.

Example:

>>> TestString = "saaaay yes no yaaaass" >>> print testString. strip ('put') yes no # prefix and end with a space >>> print testString. strip ('put') es no # There is no space at the beginning and end> print testString. lstrip ('put') yes no yaaaass # starts with a space >>> print testString. rstrip ('say') saaaay yes no # end with a space >>>

You can understand this chart based on the selected status in the editor.

The above is all the content of this article. I hope you will like it.

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.