▼ Show 1 Answer

0 votes
by

Spaces can be removed from a string in python by using strip() or replace() functions.

 Strip() function is used to remove the leading and trailing white spaces while the replace() function is used to remove all the white spaces in the string:

string.replace(” “,””) ex1: str1= “great learning”

print (str.strip())

o/p: great learning

ex2: str2=”great learning”

print (str.replace(” “,””))

o/p: greatlearning

Python
Learn More with Madanswer
...