+= only works if the statement would also work with an = sign, i.e. the left-hand side can be assigned to. This is because a += b actually becomes a = a.__iadd__(b) under the hood. So if a is something that can't be assigned to (either by syntax or semantics), such as a function call or an element of an immutable container, the += version will fail.
Example 1: Function calls
You can't assign to a function call (the syntax of Python forbids it), so you also can't += a function call's result directly:
list1 = [5, 6] list2 = [7, 8] def get_list(): return list1 get_list().extend(list2) # works get_list() += list2 # SyntaxError: can't assign to function call
Example 2: Element of immutable container
A perhaps weirder case is when the list is an element of an immutable container, e.g. a tuple:
my_tuple = ([1, 2], [3, 4], [5, 6]) my_tuple[0].extend([10, 11]) # works my_tuple[0] += [10, 11] # TypeError: 'tuple' object does not support item assignment
Since you can't do my_tuple[0] = something, you also can't do +=.
To sum up, you can use += if you can use =.
.__iadd__()/.__add__()/.__radd__()versus.extend()