+1 vote
in Python by
edited by
How to remove spaces from a string in Python?

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

Related questions

0 votes
asked Jan 3 in Python by DavidAnderson
0 votes
asked Jan 3 in Python by DavidAnderson
...