I\'m going through some old code trying to understand what it does, and I came across this odd statement:
*x ,= p
p
is a list in t
*x ,= p
is basically an obfuscated version of x = list(p)
using extended iterable unpacking. The comma after x
is required to make the assignment target a tuple (it could also be a list though).
*x, = p
is different from x = p
because the former creates a copy of p
(i.e. a new list) while the latter creates a reference to the original list. To illustrate:
>>> p = [1, 2]
>>> *x, = p
>>> x == p
True
>>> x is p
False
>>> x = p
>>> x == p
True
>>> x is p
True