[Tutor] "local variable 'l1' referenced before assignment"
drumond.douglas at gmail.com
Sat Jun 28 09:11:40 CEST 2008
> But if you don't have l1 defined yet, you can't add to l2
> It's like:
> def a2():
> l1 = foo + l2
> UnboundLocalError: local variable 'foo' referenced before assignment
> It's because l1 (and foo at above example) is a local variable.
> a1's l1 is different from a2's l1.
> Sorry to be dense, but how, in what way, is a1's l1 different from a2's
> l1"? Both are [1,2,3]*100 .
Both contain same value, but are in different namespaces (so, different
context and different memory areas).
If you do a="spam" and b="spam", this doesn't make them same variable, they
just have same value.
So is in that code. But to make it more confusing, names were the same.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor