I stumbled upon x = [m]*n
and running it in the interpreter I can see that the code allocates an n-element list initialized with m. But I can't find a description of this type of code online. What is this called?
>>> [0] * 7
[0, 0, 0, 0, 0, 0, 0]
From the Python docs' description, the multiplication operator *
used between an integer n
and a primitive sequence type performs sequence repetition of the items in the sequence n
times. So I suppose the term you are looking for is sequence repetition. Note that this is not "sequence copying", as no copies of the items are created - you have n
references to the very same sequence.