Remove Whitespace in Python
Remove all whitespace characters from a string.
BeginnerString ProgramsExample 7 of 25
remove-whitespace.py
Run in browser1# Program to remove all whitespace from a string23s = input("Enter a string: ")45no_space = "".join(ch for ch in s if not ch.isspace())67print("Without whitespace:", no_space)
Output
Enter a string: hello world Without whitespace: helloworld
What's going on
We filter out characters for which .isspace() is True.