It is a method string in python that removes all the leading characters from the right side of the string. It uses space as a default leading value. Leading characters can be one or many.
Syntax:
string.rstrip(leading_characters)
Example 1:
s = ” CodeWindow “ x = s.rstrip() print(x)
Output:
CodeWindow
Explanation:
Here the leading character by default is space which has been removed from the right side of the original string.
Example 2: s = “——-CodeWindow——–“ x = s.rstrip(“–“) print(x)
Output:
——-CodeWindow
Explanation:
Here the leading character is “–” which has been removed from the right side of the original string.
Example 3:
s = “.,,,,codeWindowssoo,,–“ x = s.rstrip(“,.-so“) print(x)
Output:
.,,,,codeWindow
Explanation:
Here the leading characters that needs to be removed are “,” “.” “–” “s” “o”. These characters are removed from the right side of the string.