4 ms·
My guess is that it's optimized, but I don't know. Semantics-wise, it's consistent with list addition. >>> [0] + [0] + [0] [0, 0, 0] >>> [0] * 3
by Goladus 15y ago
My guess is that it's optimized, but I don't know. Semantics-wise, it's consistent with list addition.
>>> [0] + [0] + [0]
[0, 0, 0]
>>> [0] * 3
[0, 0, 0]
- Ixiaus 15y agoI just read, that syntax is sugar for the list.extend() method so it's still making copies of the list - I wouldn't use it for a list containing complex objects; but that is very idiomatic for simple use cases (like this one?).