3 ms·
What. Python's `sum()` works on anything that defines `__add__`, which can be numbers, strings, lists, or your own custom classes. sum([[1, 2], [3, 4]], [])
by nine_k 6y ago
What. Python's `sum()` works on anything that defines `__add__`, which can be numbers, strings, lists, or your own custom classes.
sum([[1, 2], [3, 4]], []) == [1, 2, 3, 4]
- nitroll 6y agoActually it seems sum is special cased to fail for strings, but otherwise you are correct