On 12/11/2007, Ryan Hughes <[EMAIL PROTECTED]> wrote: > Why does the following not return [1,2,3,4] ? > > >>> x = [1,2,3].append(4) > >>> print x > None
List methods like .append() and .sort() modify lists in-place, as opposed to creating new lists. To remind you of this, those methods return None instead of returning the modified list. Otherwise (if .append() returned the modified list), you might be tempted to write code like this: x = getSomeList() y = x.append(3) and forget that x and y are the same list. If you want to join two lists together to make a new one, you can use +: >>> x = [1, 2, 3] + [4] >>> x [1, 2, 3, 4] Hope this helps, -- John. _______________________________________________ Tutor maillist - [email protected] http://mail.python.org/mailman/listinfo/tutor
