Home >>Python String Methods >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 | Description |
---|---|
characters | It is Optional. A set of characters to be removed as trailing characters from the string |
txt = " blue "
x = txt.rstrip()
print("of all color", x, "is my favorite")
of all color blue is my favorite
str = "javaScript and Java "
str2 = str.rstrip()
print(" string1: ",str)
print(" String2: ",str2)