I need to remove spaces after a word in a string. Can this be done in one line of code?
Example:
string = " xyz " desired result : " xyz"
>>> " xyz ".rstrip() ' xyz'
more about rstrip in docs
rstrip
SilentGhost's answer is pretty neat. The only thing you need to pay attention to is that str.rstrip() returns a copy of the result, this function does not change str .
str.rstrip()
str