7 ms·
I think you're confused about the difference between [x]*4 and [x for _ in range (4)]. It's not, at any point, a difference between something being a value or r
by maxcoder4 2y ago
I think you're confused about the difference between [x]*4 and [x for _ in range (4)]. It's not, at any point, a difference between something being a value or reference.
The first code is equivalent to:
list_multiply([x], 4)
(the function is actually called list.__mul__, but that's an unimportant detail). The latter is a syntax sugar for:
out = []
for _ in range(4):
out.append(x)
(actually a bit more complex, but close enough).
When you understand it, the behavior is obvious in both cases.