Decode School

Decode School - The School for Problem Solvers

Welcome to my blog. Subscribe and get my latest blog post in your inbox.

Remove the spaces in String python

python program to get a String and remove the spaces

Sample Input 1:

Hello World
Sample  Output 1 :


Program or Solution

s1=input("Enter a String:")
for i in s1:
    if(i!=" "):


Program Explanation

visit each location in string s1, if charcter in the location is not a space then append it in s2, finally store s2 in s1. Note: String is immutable, so you cannot modify a character directly in a orginal string.