I am trying to understand how extend works in Python and it is not quite doing what I would expect. For instance:
>>> a = [1, 2, 3]
>>> b = [4, 5, 6].extend(a)
>>> b
>>>
But I would have expected:
[4, 5, 6, 1, 2, 3]
Why is that returning a None instead of extending the list?
The
extend()method appends to the existing array and returnsNone. In your case, you are creating an array —[4, 5, 6]— on the fly, extending it and then discarding it. The variablebends up with the return value ofNone.