Remove All Spaces from a String in Python Example Tutorial

21-Mar-2023

.

Admin

Remove All Spaces from a String in Python Example Tutorial

Hi Dev,

This is a short guide on removing all spaces from a string in a python example tutorial. this example will help you how to remove all spaces from a string in python. We will use how to remove all whitespace from a string in python. if you want to see an example of how to delete all spaces in string python then you are in the right place.

In this example, I will add myString variable with the hello string. Then we will use replace() function to remove all white spaces from a string in python. So, without further ado, let's see simple examples: You can use these examples with the python3 (Python 3) version.

Example


main.py

# Declare String Variable

myString = "Hello, This is nicesnippets.com, This is awesome."

# Python string remove all spaces

myString = myString.replace(" ", "")

print(myString)

Output:

Hello,Thisisnicesnippets.com,Thisisawesome.

#Python