Ilya_Gazman Ilya_Gazman - 1 year ago 72
Python Question

What does the star (*) operator with a number mean?

I been reading What does the Star operator mean?, but I can't understand how the numbers come in. Could you explain to me the next expression:

squares = [x**2 for x in range(10)]

It's taken from the docs v3.5

Answer Source

This is x raised to the power 2.

Expanded out, the list comprehension has the meaning:

 x_2 = []
 for x in range(0,10):
    x_2.append(x**2)  # Take x to the power 2
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download