我正在使用 CPython,并且在一个带有星号的示例文件中看到。
您能否解释一下在这种情况下*
是什么?符号的意思是?
这里是pointsets
是 numpy array
来自pybind11
,因为它是 C++ 代码的输出。
Point(*point)
是吗?与 C++ 中的指针有关吗?
polylines = []
for points in pointsets:
points = [Point(*point) for point in points]
polyline = Polyline(points)
polylines.append(polyline)
最佳答案
它被称为解包运算符。 以下是文档中的内容:
An asterisk
*
denotes iterable unpacking. Its operand must be an iterable. The iterable is expanded into a sequence of items, which are included in the new tuple, list, or set, at the site of the unpacking.
它很像 Javascript ES6 中的“...
”运算符。 (the spread operator)
https://docs.python.org/3/reference/expressions.html#expression-lists
关于Python 循环中的星号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70621142/