nested lists - utter newbie

Benjamin Niemann pink at odahoda.de
Fri Jul 1 06:37:54 EDT 2005


rahoool at gmail.com wrote:

> Hi,
> why is this possible -
>>>>b = [1,2,3]
>>>>b[2] = b
>>>>b
> [1,2,[...]]
>>>>b[2]
> [1,2,[...]]
>>>>b[2][2][2][2][2]
> [1,2,[...]]
> 
> but this is not -
>>>>x = [1,2,x]
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> NameError: name 'x' is not defined

Because the right hand side ('[1,2,x]') is evaluated *before* the value is
bound to the name 'x' - and at this point there is obviously no name 'x'
defined.

-- 
Benjamin Niemann
Email: pink at odahoda dot de
WWW: http://www.odahoda.de/



More information about the Python-list mailing list