2

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)
4

1 Answer 1

2

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

2
  • Thank you this is what I was searching for. Commented Jan 7, 2022 at 12:24
  • @PetrasVestartasEPFL glad to help! consider upvoting/accepting it as an answer.
    – Tibebes. M
    Commented Jan 7, 2022 at 12:34

Not the answer you're looking for? Browse other questions tagged or ask your own question.