How to remove whitespaces from a string in Python?
Last updated 3 years, 1 month ago | 1217 views 75 5

Python | strip() Function | Remove whitespaces from a string
To remove the whitespaces and trailing spaces from the string, Python provides a strip([str]) built-in function. This function returns a copy of the string after removing whitespaces if present. Otherwise returns the original string.
string = " Python "
print(string.strip())