Python string strip() method

Python strip() method returns the cop of the string removing leading and trailing white spaces from the string. This method by default removes white spaces but if you want to remove another character then you can also do so.

Basic Syntax

string.strip([chars])

And the parameters are:

ParameterDescription
chars(Optional) This is an optional parameter if you provide a character then it will remove that char at start and end of the string. The default value is white space.

Return Value

strip() method returns the copy of the string removing spaces from front and end of the string.

Example

Following are some examples illustrating the Python strip() function.

Example 1

The output should be:

Hello Crazy Geeks
Crazy Geeks
Hello Crazy Geeks

Example 2

The output should be:

Hello Crazy Geeks
HelloCrazy

LEAVE A REPLY

Please enter your comment!
Please enter your name here