list.extend([]) Question

Alf P. Steinbach alfps at start.no
Sat Jan 30 10:38:07 EST 2010


* Dan Brown:
> Why does extending a list with the empty list result in None?  It
> seems very counterintuitive to me, at least --- I expected ['a'].extend
> ([]) to result in ['a'], not None.

It does.

'extend' is an operation that /modifies/ the array.

It just returns None as its expression result, in the same way as e.g. the 
Python 3.x 'print' (another pure "doer" operation).

   >>> L = ['a']
   >>> L
   ['a']
   >>> L2 = L.extend( [] )
   >>> L2
   >>> L2 is None
   True
   >>> L
   ['a']
   >>> _


Cheers & hth.,

- Alf



More information about the Python-list mailing list