list.append()方法的返回值是None,在使用时不要把list.append赋值给另一个list,这会导致list值为空,append方法会改变原list。
错误使用方式
l = []
s = 'abcde'
for i in s:
l = l.append(i)
[OUT]:Traceback (most recent call last):
File "<ipython-input-38-91b031f60ff0>", line 2, in <module>
l = l.append(a)
AttributeError: 'NoneType' object has no attribute 'append'
正确使用方式
l = []
s = 'abcde'
for i in s:
l.append(i)
print l
[OUT]:['a','b','c','d','e']