python strip space code example

Example 1: remove trailing and leading spaces in python

text = "   Hello World        "
text.strip()
# Hello World

Example 2: remove after and before space python

st = " a "
strip(st)
#Output : "a"

Example 3: delete spaces in string python

>>> s.replace(" ", "")

Example 4: python remove spaces

string=' t e s t ' 
print(string.replace(' ',''))

Example 5: strip whitespace python

>>> s.strip()
'Hello  World   From Pankaj \t\n\r\tHi There'

Example 6: python string remove whitespace

' sss d ssd s'.replace(" ", "")
# output: 'sssdssds'