How do I trim whitespace from a string in Python?

You can use Python in-built methods strip(), lstrip() or rstrip() to trim whitespace from a strip as shown in the below example –

Leave a Reply