0

Why does the second statement print out "None"? Shouldn't Python simply recognize list-variable loe as a list already, and simply append one more to the list? After all, the first print statement does recognize loe as a list.

loe = ["a", "b"]
one = "c"
print "List of elements: ", loe
print "List of elements and one: ", loe.append(one)

------------
Output:
List of elements:  ['a', 'b']
List of elements and one:  None

Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
user1972031
  • 547
  • 1
  • 5
  • 19

1 Answers1

1

list.append() does not have return value. So you got None

Jacky1205
  • 3,273
  • 3
  • 22
  • 44
  • Exactly. Many Python operations that you'd think would have a return value (e.g. `list.append`, `set.add`, `dict.update`) return `None`. Python generally doesn't support a [fluent API style](https://en.wikipedia.org/wiki/Fluent_interface) or *en passant* operations, unlike JavaScript and some other languages. – Jonathan Eunice Jan 11 '16 at 07:02