There are two main differences. Firstly, + closer in value to extend than to append :
>>> a = [1, 2, 3] >>> a + 4 Traceback (most recent call last): File "<pyshell#13>", line 1, in <module> a + 4 TypeError: can only concatenate list (not "int") to list >>> a + [4] [1, 2, 3, 4] >>> a.append([4]) >>> a [1, 2, 3, [4]] >>> a.extend([4]) >>> a [1, 2, 3, [4], 4]
Another, more noticeable difference is that the methods work in place: extend actually looks like += - in fact it has exactly the same behavior as += , except that it can accept any iterative, and += can only accept another list.
lvc
source share