Why does list.append() return None?
Just replace a_list = a_list.append(r)
with a_list.append(r)
.
Most functions, methods that change the items of sequence/mapping does return None
: list.sort
, list.append
, dict.clear
...
Not directly related, but see Why doesn’t list.sort() return the sorted list?.
The method append
does not return anything:
>>> l=[]
>>> print l.append(2)
None
You must not write:
l = l.append(2)
But simply:
l.append(2)
In your example, replace:
a_list = a_list.append(r)
to
a_list.append(r)