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.