The rstrip() function in python removes the trailing characters in the copy of the original string based on the arguments given. The method returns this copy as output.
string.rstrip([chars]) #where chars are those to remove from right
The rstrip() function takes a set of characters as its parameter. If chars are not provided the trailing space is removed from the string.
|Parameter||Description||Required / Optional|
|chars||characters to remove as trailing characters||Optional|
The return value is always a string. Until the first match found, all combinations of characters are removed from the right onwards.
|string||copy of string|
string1 = " python " string2 = string1.rstrip() print("of all programming languages", string2, "is my favorite")
of all programming languages python is my favorite
# Variable declaration string1 = "Python and Java* " # Calling function string2 = string1.rstrip(*) # Displaying result print("Before strip: ",string1) print("After strip: ",string2)
Before strip: Python and Java* After strip: Python and Java