[Tutor] Why does this NameError appear?

Alan G alan.gauld at freenet.co.uk
Thu Jul 28 01:47:25 CEST 2005

> Subject: [Tutor] Why does this NameError appear?

> lista = [x0, x1, x2, x3]
> listb = [a0, a1, a2, a3]

So what are x0, x1 etc? You haven't told Python, 
its never heard of them at this point, so...

>     lista = [x0, x1, x2, x3]
> NameError: name 'x0' is not defined

It tells you so.

You need to either make the list contents literal values
(by making x0, x1 etc strings) or initialise the variables 
before putting them into the list:

x0,x1,x2,x3 = (1,2,3,4)

As an example...

Alan G.

More information about the Tutor mailing list