Home > Backend Development > Python Tutorial > What does strip mean in python?

What does strip mean in python?

(*-*)浩
Release: 2019-06-24 16:28:20
Original
16816 people have browsed it

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]);
Copy after login

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( '*' ))  # 指定字符串 *
Copy after login

The output results of the above examples are as follows:

this is **string** example....wow!!!
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template