Liran Ben Haim Liran Ben Haim - 2 months ago 7x
Python Question

Lists in Python

I noticed that you can multiply list by scalar but the behavior is weird
If I multiply:

[2,3,4] * 3

I get:


I understand the results but what it's good for? Is there any other weird operations like that?


The main purpose of this operand is for initialisation so for example if you want to initialise a list with 20 equal numbers you can do it using a for loop:

 for i in range(20):

alternative way will be using this operator:

 arr = [3] * 20

more weird and normal list operation on lists you can find here