by maxcoder4 · 2y ago · 0 comments
Well, of course. It's a shorthand for duplicating the list elements four times. In this case, the list contains a single reference to an empty list, do the result contains four references to an empty list.
It would be bad for this case, though. As confusing as the particular case of:
[[]] * 4
might be to people who haven't learned how it works, list multiplication doesn't just apply to single element lists, and is useful and usefully distinct from what people are suggesting the behavior should be for the operation based on this one case.Besides, that still doesn't help with the case of
x = function_that_returns_a_list()
x = x * 4
where there is no literal list expression.