On Sunday November 11, 2007, Ryan Hughes wrote: > Hello, > > Why does the following not return [1,2,3,4] ? > > >>> x = [1,2,3].append(4) > >>> print x > None
The reason is that the append method does not return anything. In effect, the expresison [1,2,3].append(4) temporarily causes 4 to be appended to the (unnamed) list. However the assignment x = blah sets the variable x equal to the result of the expression blah (which in this case is None, since append does not return anything). In contrast, consider the following interaction: >>> x = [1,2,3] >>> x.append(4) >>> print x [1, 2, 3, 4] _______________________________________________ Tutor maillist - [email protected] http://mail.python.org/mailman/listinfo/tutor
