python remove trailing and leading whitespace in string code example Example: remove trailing and leading spaces in python text = " Hello World " text.strip() # Hello World