2

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

>>> print [1].append(2)
None
jwodder
  • 50,627
  • 10
  • 99
  • 112
Rob Bednark
  • 22,937
  • 20
  • 77
  • 112

2 Answers2

9

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

>>> print [1].append(2)
None
Karoly Horvath
  • 91,854
  • 11
  • 113
  • 173
  • 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
  • 59,667
  • 7
  • 131
  • 173