繁体   English   中英

无法使用 Python 删除字符串上的空格

[英]Unable To Remove Whitespace On String Using Python

我正在尝试摆脱此列表中的空白,但我无法做到。 有人知道我的代码哪里出错了吗?

 love_maybe_lines = ['Always    ', '     in the middle of our bloodiest battles  ', 'you lay down your arms', '           like flowering mines    ', '   to conquer me home.    ']
    
    love_maybe_lines_joined = '\n'.join(love_maybe_lines)
    love_maybe_lines_stripped = love_maybe_lines_joined.strip()
    print(love_maybe_lines_stripped)

Terminal: 

Always    
     in the middle of our bloodiest battles  
you lay down your arms
           like flowering mines    
   to conquer me home.
love_maybe_lines = ['Always    ', '     in the middle of our bloodiest battles  ', 'you lay down your arms', '           like flowering mines    ', '   to conquer me home.    ']

love_maybe_lines = [item.strip() for item in love_maybe_lines]

这可能会有所帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM