Why can't I do this:
d = [x for x in range(7)]
a, b, c, d, e, f, g = *d
Where is it possible to unpack? Only between parentheses of a function?
Why can't I do this:
d = [x for x in range(7)]
a, b, c, d, e, f, g = *d
Where is it possible to unpack? Only between parentheses of a function?
You're using Extended Iterable Unpacking
in wrong way.
d = [x for x in range(7)]
a, b, c, d, e, f, g = d
print(a, b, c, d, e, f, g)
Where it's possible to unpack? Only between parentheses of a function?
No,
*
proposes a change to iterable unpacking syntax, allowing to specify a "catch-all" name which will be assigned a list of all items not assigned to a "regular" name.
You can try something like this:
a, *params = d
print(params)
Output
[1, 2, 3, 4, 5, 6]
Usually *
(Extended Iterable Unpacking) operator is used when you need to pass parameters to a function.
Note
Javascript equivalent of Extended Iterable Unpacking operator
is called spread syntax.
d = [...Array(7).keys()]
console.log(d)
var [a, ...b] = d
console.log(a,b)