Skip to main content

How to replace blank spaces in string in python

Below code will replace blank spaces from string and print output.

str1= input('enter string to replace blank spaces')
print('String before replace -->',str1)
str2=str1.replace(" ","")
print('String after replace---->',str2)


String before replace --> This is Python Language
String after replace----> ThisisPythonLanguage