Python String strip() Method


Advertisements


Description

The method strip() 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.

Live Demo
#!/usr/bin/python

str = "0000000this is string example....wow!!!0000000";
print str.strip( '0' )

When we run above program, it produces following result −

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

python_strings.htm

Advertisements