Hacker News new | ask | show | jobs
by krenel 2310 days ago
Operators are polymorphic. While the + operator is commutative when using on integers/float, it is not currently when used on lists:

>>> [1,2,3] + [4,5,6]

[1, 2, 3, 4, 5, 6]

>>> [4,5,6] + [1,2,3]

[4, 5, 6, 1, 2, 3]

In dictionaries it would behave differently as well (duplicated keys, etc.)

1 comments

It's also not commutative on strings and that is the case in many languages, not just Python.