Remove the spaces in String python

python program to get a String and remove the spaces

Sample Input 1:

Hello World
Sample  Output 1 :

HelloWorld

Try your Solution

Strongly recommended to Solve it on your own, Don't directly go to the solution given below.

#write your code here

Program or Solution

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


			
				
			

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.

Comments