How to remove whitespaces from a string in Python?

Last updated 3 weeks, 5 days ago | 17 views 75     5

Tags:- Python

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())