1

I was surprised to learn that

[] = []

is a perfectly valid Python statement (with no effect). Also:

[] = tuple()
[] = set()
[] = {}

I gather it's trying to unpack the iterables on the right hand side, but what's an iterable doing on the left hand side of an assignment?

Eli Rose
  • 6,788
  • 8
  • 35
  • 55
  • Also relevant: http://stackoverflow.com/questions/29870019/why-is-it-valid-to-assign-to-an-empty-list-but-not-to-an-empty-tuple – poke Jun 12 '15 at 06:31
  • 1
    Sooooo many up-votes are on their way for not much of a reason :) – Hanky Panky Jun 12 '15 at 06:32
  • @Hanky웃Panky: the reason is probably the OP couldn't find the duplicate answer when searching before asking (I know I couldn't). This is the nth this happened by the way, I'm thinking the canonical answer should be renamed (don't have an idea). Or, you know, just wait for the duplicates to saturate the search space of the relevant phrase :p. – mikołak Jun 12 '15 at 06:33
  • @mikołak Good idea; I attempted to give it a better name. – poke Jun 12 '15 at 06:37
  • @poke: yeah, that's slightly better, at least people looking via a textual description are more likely to find it now - thanks! Also, see [this meta question](http://meta.stackoverflow.com/questions/296742/searching-for-a-phrase-including-square-brackets-how-to-make-it-work). – mikołak Jun 12 '15 at 06:52

0 Answers0