Python String strip method with Example – Python Tutorial

4 weeks ago codedestine 0

In this tutorial, we will learn about python string strip method.
Python String strip

strip method :

This method returns a copy of the string in which all the occurrences of chars ( passed as an argument ) has been removed from both beginning ( left side ) and end ( right side ) of the string object. If chars arguments is omitted or None, then chars argument defaults to whitespace.

Syntax : < String Object >.strip( [ chars ] ) :  < String Object >

              chars: characters to be removed.

Example:

# create one string and assign it to variable s1 s1 = ' strip example ' # call strip() method on string s1 output = s1.strip() # print the value of variable output print(output) # create one string and assign it to variable s2 s2 = 'strip example strip' # call strip() method on string s2 by passing 'strip' as an argument output = s2.strip('strip') # print the value of variable output print(output)

References :-

  1. strip() method Docs

That’s all for Python String strip method. If you liked it, please share your thoughts in comments section and share it with others too.

Previous