Remove Whitespace
Remove all whitespace characters from a string.
BeginnerTopic: String Programs
Python Remove Whitespace Program
This program helps you to learn the fundamental structure and syntax of Python programming.
# Program to remove all whitespace from a string
s = input("Enter a string: ")
no_space = "".join(ch for ch in s if not ch.isspace())
print("Without whitespace:", no_space)Output
Enter a string: hello world Without whitespace: helloworld
Understanding Remove Whitespace
We filter out characters for which .isspace() is True.
Note: To write and run Python programs, you need to set up the local environment on your computer. Refer to the complete article Setting up Python Development Environment. If you do not want to set up the local environment on your computer, you can also use online IDE to write and run your Python programs.