【解决方案1】:

试试

a = '  hello   world'
a.strip()

【讨论】:

  • O(n), ***.com/a/27684660/17047120
  • 这只从左右剥离。