Oct-15-2017, 10:37 PM
I've done what I should probably have done in the first place; read the spec. I think I basically understand now but htere's one thing still bothering me.
There is a difference between () and [] on the LHS of an assignment but it's quite subtle.
So
I'm guessing this use of parenthesis is to be consistent with the rules for creating tuples and lists. In
E.G.
There is a difference between () and [] on the LHS of an assignment but it's quite subtle.
(a) =
is the same as a =
[a] =
requires an iterable on the RHS (with just one value)So
(a) = 2
is valid but [a] = 2
is not.I'm guessing this use of parenthesis is to be consistent with the rules for creating tuples and lists. In
(1,2)
the parentheses don't make this a tuple, the comma does. The parentheses are, actually (redundant) "ordering" parentheses as in (2 + 3)
. On the LHS they do the same thing. E.G.
a,(b,) = 1, 2 #invalid a,(b,) = 1, 2, #invalid a,(b,) = 1, (2,) #OK a,(b,) = 1, (2) #invalid a, b = 1, 2, #OK a, b, = 1, 2 #OKBut, what I still don't get is why allow [] on the RHS at all.
a,
requires and iterable on the RHS just like [a]
. I.E.:(a) = 1, #a is a tuple. [b] = 2, #b is an integer #but so is c in c, = 1,I can't see a need for [] on the LHS so it seems odd to allow them. Especially given the confusion with lists and tuples.