如何切断最后一个空白空间?
a = ['Hello ','everybody ','! ']
for i in range(len(a)):
a[i,-1]=''
print a
最佳答案
通过list comprehension解决方案:
>>> a = ['Hello ','everybody ','! ']
>>> [ e.strip() for e in a ]
['Hello', 'everybody', '!']
文档:分别为
string.strip
/ string.rstrip
,string.lstrip