Topic: Remove Spaces from String using Python.

Hey Guys, today we are going see a Python Program to remove spaces from a string using user input.

Title: Python Code to Remove Spaces from String. (Beginner Friendly + Easy + Code + Output + Online Compiler)


What is this program and why we are going to use it?

This Program consists of Variables, Input Function, Loop (for loop) and String Manipulation.

By using variables, we store string input from the user. By using input function, we take input from the user. For example:
s = "hello world"
Here s is a variable where "hello world" is assigned to s.

We remove spaces by checking each character and rebuilding the string.

s = input("Enter a string: ")
So, this will ask user to input a string.

Logic:

1. Take a string (s) from user.
2. Initialize an empty string result = "".
3. Loop through each character in string.
   - If character is not a space → add to result
4. Display the final string without spaces.

Code:


Online Compiler (Switch to Interactive Mode before execution):



Example Output:

Input: hello world
Output: helloworld

Applications:

1. Used in data cleaning and preprocessing
2. Helps in understanding string manipulation
3. Useful in text formatting tasks

Comments