带数字的星号(*)运算符是什么意思?

问题描述:

我一直在读What does the Star operator mean?,但我不明白这些数字是怎么来的,你能不能给我解释下表达:带数字的星号(*)运算符是什么意思?

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

它从docs V3.5

+3

阅读[list comprehension](http://www.secnetix.de/olli/Python/list_comprehensions.hawk)。 –

+1

这是电力运营商。 'x ** 2'表示*'x'平方*,而'x ** 3'表示*'x'表示第三个功率*。有些语言使用'^'来代替(例如,'x^2'代表'x'),但在Python中,^是XOR位运算符。它完全不**在'f(** arguments)'中使用'**'或'*'。 – Bakuriu

采取这是x幂2.

向外扩张,列表理解的含义:

x_2 = [] 
for x in range(0,10): 
    x_2.append(x**2) # Take x to the power 2 
+1

我应该猜测它,lols –

* # is the multiplication operator expression: 

** # power operator so 3**2 = 9 

下面是一个列表理解:

[f(x) for x in iterator] 

因此它创建与f(x)的每个x列表由iterator

作为返回在这种情况下F(X)=升华到的2

范围(10)的功率是数字0 - > 9

所以对于每个该宏将会数l返回那个数字,上升到2的幂0