Home >>Python String Methods >Python String rstrip() Method

Python String rstrip() Method

Python String rstrip() Method

Python String rstrip() Method in python returns a copy of the string by removing all the trailing characters (based on the string argument passed) from right side of the string, it removes all the trailing spaces, if no arguments is passed.

Syntax:
string.rstrip(characters)

Parameter Values

Parameter Description
characters It is Optional. A set of characters to be removed as trailing characters from the string
Here is an Example of Python String rstrip() Method:

txt = "     blue     "
x = txt.rstrip()
print("of all color", x, "is my favorite")

Output:
of all color      blue is my favorite
Example 2:

str = "javaScript and Java "  
str2 = str.rstrip()  
print(" string1: ",str)  
print(" String2: ",str2)

Output:
string1: javascript and Java
String2: javascript and Java

No Sidebar ads