text = " Hello World "
text.strip()
# Hello World
Use the strip() method
Example
>>> name = ' Steve '
>>> name
' Steve '
>>> name = name.strip()
>>> name
'Steve'
Use the rstrip() method
Example
>>> name = ' Steve '
>>> name
' Steve '
>>> name = name.rstrip()
>>> name
' Steve'