我一直在讀What does the Star operator mean?,但我不明白這些數字是怎麼來的,你能不能給我解釋下表達:帶數字的星號(*)運算符是什麼意思?
squares = [x**2 for x in range(10)]
它從docs V3.5
我一直在讀What does the Star operator mean?,但我不明白這些數字是怎麼來的,你能不能給我解釋下表達:帶數字的星號(*)運算符是什麼意思?
squares = [x**2 for x in range(10)]
它從docs V3.5
採取這是x
冪2.
向外擴張,列表理解的含義:
x_2 = []
for x in range(0,10):
x_2.append(x**2) # Take x to the power 2
我應該猜測它,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
閱讀[list comprehension](http://www.secnetix.de/olli/Python/list_comprehensions.hawk)。 –
這是電力運營商。 'x ** 2'表示*'x'平方*,而'x ** 3'表示*'x'表示第三個功率*。有些語言使用'^'來代替(例如,'x^2'代表'x'),但在Python中,^是XOR位運算符。它完全不**在'f(** arguments)'中使用'**'或'*'。 – Bakuriu