CKTIS / Python
Operator *=
Repeats a mutable sequence in place when the right operand is an integer.
Version: Python 3.14; repository image, production runtime not attested
Syntax
target *= valueRepeats a mutable sequence in place when the right operand is an integer.
Integer targets are replaced by the numeric product. A list instead repeats its contents in the same list when its right operand is an integer count.
Repetition preserves element references. Repeating a nested list can therefore create several positions observing the same inner mutable list.
Repeating a list zero times in place clears it while keeping existing aliases.
Syntax
target *= value
__imul__, __mul__, __rmul__ · TypeError
Worked example
a = [7]; b = a; a *= 0
b → []
a is b → True
Examples
value = ["x"]
another = value
value *= 0
print(value)
print(another is value)
Result
[] True
Repeating a list zero times in place clears it while keeping existing aliases.