Python 3 - String strip() Method


Description

The strip() method returns a copy of the string in which all chars have been stripped from the beginning and the end of the string (default whitespace characters).

Syntax

Following is the syntax for strip() method −

str.strip([chars]);

Parameters

chars − The characters to be removed from beginning or end of the string.

Return Value

This method returns a copy of the string in which all chars have been stripped from the beginning and the end of the string.

Example

The following example shows the usage of strip() method.

#!/usr/bin/python3

str = "*****this is string example....wow!!!*****"
print (str.strip( '*' ))

Result

When we run above program, it produces the following result −

this is string example....wow!!!
python_strings.htm
Advertisements