list1.append(list2) returns None

Ben Finney bignose+hates-spam at benfinney.id.au
Thu Dec 21 00:29:01 EST 2006


Pyenos <pyenos at pyenos.org> writes:

> def enlargetable(table,col):
>     return table.append(col)
>
> def removecolfromtable(table,col):
>     return table.remove(col)
>
> print enlargetable([[1],[2],[3]],[4]) # returns None
>
> Why does it return None instead of [[1],[2],[3],[4]] which I expected?

The answer is both "because that's what it's documented to do":

    s.append(x)    same as s[len(s):len(s)] = [x]
    <URL:http://docs.python.org/lib/typesseq-mutable.html>

and "because you asked it to *do* something, not *get* something":

    <URL:http://www.python.org/doc/faq/general.html#why-doesn-t-list-sort-return-the-sorted-list>

-- 
 \            "There was a point to this story, but it has temporarily |
  `\                 escaped the chronicler's mind."  -- Douglas Adams |
_o__)                                                                  |
Ben Finney




More information about the Python-list mailing list