Sometimes, we want to fix appending turns my list to NoneType with Python.
In this article, we’ll look at how to fix appending turns my list to NoneType with Python.
How to fix appending turns my list to NoneType with Python?
To fix appending turns my list to NoneType with Python, we shouldn’t assign the return result append
to the list.
For instance, instead of writing
a_list = ['a', 'b', 'c', 'd']
a_list = a_list.append('e')
We write
a_list = ['a', 'b', 'c', 'd']
a_list.append('e')
since append
appends 'e'
to a_list
in place and returns nothing.
Conclusion
To fix appending turns my list to NoneType with Python, we shouldn’t assign the return result append
to the list.