How do I trim whitespace from a string?
To remove all whitespace surrounding a string, use .strip(). Examples: >>> ‘ Hello ‘.strip() ‘Hello’ >>> ‘ Hello’.strip() ‘Hello’ >>> ‘Bob has a cat’.strip() ‘Bob has a cat’ >>> ‘ Hello ‘.strip() # ALL consecutive spaces at both ends removed ‘Hello’ Note that str.strip() removes all whitespace characters, including tabs and newlines. To remove only … Read more