list1.append(list2) returns None

Steven D'Aprano steve at REMOVEME.cybersource.com.au
Thu Dec 21 00:48:24 EST 2006


On Thu, 21 Dec 2006 16:29:01 +1100, Ben Finney wrote:

> 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":

Documentation is a funny thing... 

help([].append)

Help on built-in function append:

append(...)
    L.append(object) -- append object to end



Sometimes it is hard to tell when you've read enough documentation.
However, as a general rule, "None whatsoever" is rarely enough.



-- 
Steven 




More information about the Python-list mailing list