Python string rstrip() method
Remove spaces (or other characters) from the right end only.
Syntax
str.rstrip(chars=None)
Often used to remove the new line at the end of a line read from a file.
Parameters
| chars | the characters to remove |
Return value
str
Example
Code
line = "last line\n" print(repr(line.rstrip())) print("price: 12.50$".rstrip("$"))
Output
'last line' price: 12.50
Related
Learn it step by step in the free lesson Strings, with exercises that check your answers.