How to remove leading and trailing spaces from a string in Python

Removing leading and trailing spaces from a string eliminates all whitespace before the first character and after the last character in the string. For example, removing leading and trailing spaces from ” abc def ” results in “abc def”

Solution for How to remove leading and trailing spaces from a string in Python : You can use str.strip() to remove leading and trailing spaces from a string Call str.strip() to trim all leading and trailing whitespace from the string str.


how-to-remove-leading-and-trailing-spaces-from-a-string-in-python