可以使用列表推导式和字符串的'strip()'方法来实现。'strip()'方法用于去除字符串的前后空格。

示例代码如下:

lst = ['  hello ', '  world  ', 'python  ']
new_lst = [s.strip() for s in lst]
print(new_lst)

输出结果为:

['hello', 'world', 'python']
Python 列表字符串去除前后空格 -  高效简洁方法

原文地址: http://www.cveoy.top/t/topic/gELS 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录