Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python star symbol in a loop

I am using CPython and I saw in one example file with a star symbol.
Could you give an explanation what in this context the * symbol means?
Here the pointsets is a numpy array that comes from pybind11, because it is an output of C++ code.

Does the Point(*point) has something to do with the pointers in C++?

polylines = []
for points in pointsets:
    points = [Point(*point) for point in points]
    polyline = Polyline(points)
    polylines.append(polyline)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

It’s called unpacking operator.
Here is what’s written in the docs:

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.

It is much like the "..." operator from Javascript ES6. (the spread operator)

https://docs.python.org/3/reference/expressions.html#expression-lists

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading