Why does list.append evaluate to false in a boolean context?

Viewed 12787

Is there a reason being list.append evaluating to false? Or is it just the C convention of returning 0 when successful that comes into play?

>>> u = []
>>> not u.append(6)
True
7 Answers

The list.append function returns None. It just adds the value to the list you are calling the method from.

Here is something that'll make things clearer:

>>> u = []
>>> not u
False
>>> print(u.append(6)) # u.append(6) == None
None    
>>> not u.append(6) # not None == True
True
Related