logo

Python String Strip() Method


Show

Description

The strip() method in Python String returns a copy of the string where all the chars have been stripped right from the beginning and also the end of the string consisting of default whitespace characters. The strip() method thus returns a copy of the string that consists of both leading and trailing characters removed (depending on the string argument passed). The strip() method in Python string removes the characters from both left as well as right depending on the argument (a string that specifies the set of characters that are to be removed).

Syntax

Here is the syntax for strip() method:

str.strip([chars]);

Parameters

  • str - This refers to the string to be checked.
  • beg - This is the optional parameter in order to set start index of the matching boundary.
  • end - This is the optional parameter that end start index of the matching boundary.

Return Value

This method in Python string returns true if in case it is found matching with the string otherwise false.

Example

The following example below shows the usage of startswith() method.

#!/usr/bin/python

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

When the above program is run, it produces the following result:

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

Here at Intellinuts, we have created a complete Python tutorial for Beginners to get started in Python.