Remove leading and trailing spaces?

后端 未结 4 1420
醉梦人生
醉梦人生 2020-12-07 19:57

I\'m having a hard time trying to use .strip with the following line of code.

Thanks for the help.

f.write(re.split(\"Tech ID:|Name:|Account #:\",li         


        
4条回答
  •  無奈伤痛
    2020-12-07 20:10

    You can use the strip() to remove trailing and leading spaces.

    >>> s = '   abd cde   '
    >>> s.strip()
    'abd cde'
    

    Note: the internal spaces are preserved

提交回复
热议问题