DenverCoder9 DenverCoder9 - 6 months ago 48
Python Question

Assigning empty list

I don't really know how I stumbled upon this, and I don't know what to think about it, but apparently

[] = []
is a legal operation in python, so is
[] = ''
, but
'' = []
is not allowed. It doesn't seem to have any effect though, but I'm wondering: what the hell ?


This is related to Python's multiple assignment (sequence unpacking):

a, b, c = 1, 2, 3

works the same as:

[a, b, c] = 1, 2, 3

What you've discovered is the degenerative case: empty sequences on both sides. Syntactically valid because it's a list rather than a tuple. Nice find; never thought to try that before!