Last updated 8 months ago
We can use string function strip to remove trailing spaces and new lines from a string.
strip
>>> "Hello World! ".strip() 'Hello World!'
Note:- We can also use rstrip and lstrip to remove spaces/new lines from left or right side of the string accordingly.
rstrip
lstrip
Source: