How to trim whitespaces of a string in Python
We can remove the leading and trailing whitespaces of a string by using the strip()
method in Python.
Here is an example that removes the whitespaces of a string
a = ' Happy Python '
print(a.strip()) # removes beginning and ending
Output:
Happy Python