Pablo Pablo - 1 year ago 84
Python Question

How do I remove whitespace from the end of a string in Python?

I need to remove whitespaces after the word in the string. Can this be done in one line of code?


string = " xyz "

desired result : " xyz"

Answer Source
>>> "    xyz     ".rstrip()
'    xyz'

more about rstrip in docs

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download