+
is implemented using list.__add__
, which expects both arguments to be instance of list
.
eq_list = eq_list + tuple1 # eq_list = list.__add__(eq_list, tuple1)
+=
is implemented using list.__iadd__
, which expects only the first argument to be an instance of list
; the second argument can be any iterable object.
eq_list += tuple1 # eq_list = list.__iadd__(eq_list, tuple1)
a += b
and a = a + b
are only equivalent when __iadd__
isn't defined for the given type. For example, tuple.__iadd__
isn't defined, so given x = ()
, both x = x + ()
and x += ()
are implemented with x = x.__add__(())
.