Home  >  Article  >  Backend Development  >  What does strip mean in python?

What does strip mean in python?

(*-*)浩
(*-*)浩Original
2019-06-24 16:28:2016634browse

Strip in python is a method in strings.

What does strip mean in python?

The Python strip() method is used to remove specified characters (spaces by default) or character sequences at the beginning and end of a string. (Recommended learning: Python video tutorial)

Note: This method can only delete the beginning or end characters, but not the middle characters.

strip() method syntax:

str.strip([chars]);

Parameters

chars -- Remove the beginning and end of the string The specified character sequence.

Return value

Returns a new string generated by removing the specified character sequence from the beginning and end of the string.

Examples

The following examples show how to use the strip() function:

#!/usr/bin/python3
str = "*****this is **string** example....wow!!!*****"
print (str.strip( '*' ))  # 指定字符串 *

The output results of the above examples are as follows:

this is **string** example....wow!!!

From the results, you can notice that the characters in the middle part have not been deleted.

For more Python related technical articles, please visit the Python Tutorial column to learn!

The above is the detailed content of What does strip mean in python?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn