Python assignment operator differs from non assignment
问题 I have face this weird behavior I can not find explications about. MWE: l = [1] l += {'a': 2} l [1, 'a'] l + {'B': 3} Traceback (most recent call last): File "<input>", line 1, in <module> TypeError: can only concatenate list (not "dict") to list Basically, when I += python does not raise an error and append the key to the list while when I only compute the + I get the expected TypeError . Note: this is Python 3.6.10 回答1: l += ... is actually calling object.__iadd__(self, other) and modifies