In Python, trying to do the most basic append function to a list with a loop:
Not sure what i am missing here:
a=[]
for i in range(5):
a=a.append(i)
a
returns:
'NoneType' object has no attribute 'append'
解决方案
The list.append function does not return any value, it just add the value to the list you are using to call that method.
In the first loop round you will assign None (because the no-return of append) to a, then in the second round it will try to call a.append, as a is None it will raise the Exception you are seing
You just need to change it to:
a=[]
for i in range(5):
a.append(i)
a # the list with the new items.