Be careful with Python's append method

TL;DR --Be careful with Python's ʻappend` method that adds an element to the end of the list.

Execution environment

hardware

item information
OS macOS Catalina(10.15.7)
hardware MacBook Pro (13-inch, 2019, Two Thunderbolt 3 ports)
Processor 1.4 GHz quad core Intel Core i5
memory 16 GB 2133 MHz LPDDR3

software

item information
language Python(3.8.5)

append method

It's not necessary to write about how to use it, but use it as follows.

$ Python
>> array = []
>> array.append('item')
>> print(array)
['item']

This ʻappend method does not return a list by itself, but returns None`.

$ Python
>> array = []
>> print(array.append('item'))
None

If you inadvertently specify ʻArray.append (Item)when passing it to the return value or argument of the function,None` will be passed. I've taken a lot of time for this today, so I'll leave it as a memorandum.

Recommended Posts

Be careful with Python's append method
⚠️ Be careful with Python's default argument values ⚠️
(Note) Be careful with python argparse
Be careful when running CakePHP3 with PHP7.2
Be careful when working with gzip-compressed text files
Kernel Method with Python
Be careful when reading data with pandas (specify dtype)
Regarding Python's Sort method
[Python3] Be careful with removing character strings (strip, lstrip, rstrip)
[Introduction to Udemy Python3 + Application] 51. Be careful with default arguments
Face recognition with Python's OpenCV
Implement subcommands with Python's argparse
Method chain with `return self`
[Python] Calculation method with numpy
Graph drawing method with matplotlib
Be careful of LANG for UnicodeEncodeError when printing Japanese with Python 3