undefined variable

Terry Reedy tjreedy at udel.edu
Sat Jan 27 15:55:42 EST 2001


"shaka" <fabrice.n at home.com> wrote in message
news:nHsc6.252522$59.63479549 at news3.rdc1.on.home.com...
>
>  hi, I am a beginner learning python, and I have notice that in python
> variables are not declared or defined.

Python does not have variables in the same sense as other languages
(fixed chunks of memory with one name attached to each).
It has PyObjects with zero to many names attached as labels and access
handles.
'Type' is a property of PyObjects.  It is declared, usually implicitly, in
the creation process.
Names, unlike variables, do not have types; each can be attached to any
object of any type.
Hence there is no type information to be declared or defined in respect to
names.

You can use a name as a variable by always rebinding it objects of the same
type.
This discipline/restriction is, however, a programmer's responsibility.

> But does it mean that your cannot use  the same variable twice
>  and all your variable have to be of different name.

In each namespace, each name is currently attached to exactly one PyObject.

> In java you can have a variable of the same name but of different type
and
> it makes programming much more flexible.

In Python, the same name can be used concurrently in more than one
namespace.

Terry J. Reedy






More information about the Python-list mailing list