4 ms·
The truly weird thing here is that [] + (2,) is a TypeError: can only concatenate list (not "tuple") to list but L = [] L += (2,) is totally c
by klyrs 5y ago
The truly weird thing here is that
[] + (2,)
is a
TypeError: can only concatenate list (not "tuple") to list
but
L = []
L += (2,)
is totally cool.
In the end, it makes sense because I can't tell you if []+() should be a tuple or a list, and even if I did, I might have a different answer for ()+[]; whereas L+=bla looks like the type of L should not change.
- maleldil 5y agoThey're different operations. The first is concatenation; the second is extension. Concatenation only works with other lists, but extension works with any iterable.