Skip to content

Instantly share code, notes, and snippets.

@mahmoud
Created January 18, 2019 06:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mahmoud/f19641c7d44922e1defb9b284951f3e7 to your computer and use it in GitHub Desktop.
Save mahmoud/f19641c7d44922e1defb9b284951f3e7 to your computer and use it in GitHub Desktop.
>>> x = [1]
>>> y = (2, 3)
>>> x + y
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can only concatenate list (not "tuple") to list
>>> x += y
>>> x
[1, 2, 3]
@kurtbrose
Copy link

This is defensible in the sense that += is asymmetric (left side is special and gets to determine type)

whereas + is meant to be symmetric -- A + B vs B + A should almost always evaluate to the same value

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment