2

Why does print [1].append(2) evaluate to None? I expect [1,2]

>>> print [1].append(2)
None
jwodder
  • 54,758
  • 12
  • 108
  • 124
Rob Bednark
  • 25,981
  • 23
  • 80
  • 125

2 Answers2

8

That's because append returns nothing (= None).

>>> print [1].append(2)
None
Karoly Horvath
  • 94,607
  • 11
  • 117
  • 176
  • 2
    I was sitting here scratching my head thinking "this really should work" and then you came around and pointed out the obvious :) – Emmett Butler Aug 30 '12 at 16:50
3

array.append doesn't return the array you appended to, it returns None.

Femaref
  • 60,705
  • 7
  • 138
  • 176