3 ms·
This is much better than my own comment - I never even knew about that syntax! Is it efficient though?
by Ixiaus 15y ago
This is much better than my own comment - I never even knew about that syntax!
Is it efficient though?
- Goladus 15y agoMy 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?).
- calpaterson 15y agoIt isn't syntax - help(list.__mul__)