Python 循环中的星号

标签 python cpython

我正在使用 CPython,并且在一个带有星号的示例文件中看到。 您能否解释一下在这种情况下*是什么?符号的意思是? 这里是pointsetsnumpy 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/

相关文章:

python - Django 管理员保存错误 : get_db_prep_value() got an unexpected keyword argument 'connection'

javascript - 屏幕截图 ala Draw Something

python - cv2.PutText vs cv2.AddText 两者有什么区别?

python - CPython 何时将未使用的 RSS 内存返回给操作系统?

python - 如何在 Pandas 中一次计算均值和标准差?

python - 在 pandas 中对 groupby 内的类别值进行排序

python - 核心 CPython 的 C 扩展模块的测试在哪里?

python - 具有 Python C 扩展的类(不是方法)的完整和最小示例?

python - 将带有内部空字符的 python2.7 字符串传递给 C++

python - 为 Python 2.7.12 安装 numpy、cython、cpython