Python String rstrip method with Example – Python Tutorial
4 weeks ago codedestine 0
In this tutorial, we will learn about python string rstrip method.
rstrip method :
This method returns a copy of the string in which all the occurrences of chars ( passed as an argument ) has been removed from the end ( right side ) of the string object on which method is called. If chars arguments is omitted or None, then chars argument defaults to whitespace.
Syntax : < String Object >.rstrip( [ chars ] ) : < String Object >
chars: characters to be removed.
# create one string and assign it to variable s1 s1 = 'rstrip example ' # call rstrip() method on string s1 output = s1.rstrip() # print the value of variable output print(output) # create one string and assign it to variable s2 s2 = 'rstrip example for' # call rstrip() method on string s2 by passing 'for' as an argument output = s2.rstrip('for') # print the value of variable output print(output)
That’s all for Python String rstrip method. If you liked it, please share your thoughts in comments section and share it with others too.