17

Possible Duplicate:
why does python's list.append evaluate to false?

In my opinion, I think list1.extend(list2) and list1.append(num) should return the mutated list rather than None (void). As well as having the side effect of destructively mutating the original list.

Community
  • 1
  • 1
user1352399
  • 295
  • 1
  • 2
  • 5
  • 5
    I personally think it is also a badly-designed API, and mutation-based APIs are bad. However this question is not appropriate for StackOverflow, since it is not a question; it is a opinion that is likely to only solicit debate. Unless we consider the title "Why does extend() and append() return None (void)?" as part of the question, which which case it is not easily answerable unless you ask the devs themselves what was going through their minds. – ninjagecko May 21 '12 at 00:08
  • 5
    Also if you desire this behavior, you can do `yourList + [1]` or `yourList + [1,2,3]`. Sadly, imperative programming styles (like python) would "normally" just throw away the return values if they were used on lines by themselves. – ninjagecko May 21 '12 at 00:10
  • @ninjagecko -a question is being asked, that question is `Why does extend() and append() return None (void)?` See this answer in particular: (http://stackoverflow.com/a/1682601/21945) – mhawke May 21 '12 at 00:17

1 Answers1

11

I believe the intent was to promote readable code and reduce bugs. This decision was made a very long time ago, but you can probably find more by looking at the archives of the python/python-dev mailing lists.

Python3 would have been the opportunity to change this behaviour, but as you see it remains, so is not considered a design mistake by the development team

John La Rooy
  • 281,034
  • 50
  • 354
  • 495