4 ms·
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,
by krenel 7y 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.)
- shawnz 7y agoIt's also not commutative on strings and that is the case in many languages, not just Python.