[Solved] What does asterix * means in Python


The operators in Python are magic. They invoke special methods depending on the class of the operand. In this case a special method called __mul__ is called from the list class, since a list object is on the left-side.

In the case of a list, the list is repeated by the number of times given on the right (the parentheses are meaningless in this case). Tuple and string (str) objects can be multiplied in a similar way.

If you want to see what the special methods are, and their corresponding operators, see the operator module documentation.

By the way, you use the term array, which is understandable coming from other languages. However [0] does not create an array, but a list object. That might sound like semantics, but arrays do exist in python, but they have a specialised use. There is an array module in the standard library, and the numpy module also has arrays, see here. For everyday use though, list is the norm.

solved What does asterix * means in Python