Python String rstrip() method
Python String rstrip() method
The string.rstrip() method in Python returns a copy of the string with trailing characters removed.
Syntax
string.rstrip([chars])
Parameter
chars: This argument represents a string specifying the set of characters to be removed. By default, the chars argument removes the whitespace.
Return
This method returns a copy of the string with trailing characters removed.
Example 1
# Python program demonstrating the use of # string.rstrip() method # string which is to be stripped string = "tutorialsssssss" # Removes the specified set of characters from the right. print(string.rstrip('s'))
Output
tutorial
Example 2
# Python program demonstrating the use of # string.rstrip() method # string which is to be stripped string = "Tutorials and Examples" print("Actual string...\n") # Removes given set of characters from # right. print("After striping 'sel' from the string...") print(string.rstrip('sel'))
Output
Actual string... Tutorials and Examples After striping 'sel' from the string... Tutorials and Examp
Example 3
# Python program explaining # the string.rstrip() method # initializing the string string = "hellloooo...,,,,,,,woorllllddddddd." print("Actual string:",string) # striping the values print("After the right striped method") val = string.rstrip(",.orld") # printing the striped value print(val)
Output
Actual string: hellloooo...,,,,,,,woorllllddddddd. After the right striped method hellloooo...,,,,,,,w