[Tutor] Re: informaton about some specific variable locaton ...
does computer needs two informations ???
alan.gauld at freenet.co.uk
Wed Nov 19 04:45:21 EST 2003
----- Original Message -----
From: "Tadey" <tayiper at volja.net>
To: "Alan Gauld" <alan.gauld at freenet.co.uk>
Sent: Wednesday, November 19, 2003 7:53 AM
Subject: informaton about some specific variable locaton ... does
computer needs two informations ???
> I have read some book about programming languages in general, and in
> about variables, it says something like (I had to translate it from
> Slovenian - as accurate as I could)
> > START <
> Access to certain location in memory is possible by addressing this
> Adress could be the name of "variable" (Note: with variable, here
> just a number which could change - more like in math, not
> variable) or "pointer" ("index", "indicator"). In programming
> name of "variable" (again math term) could means value, which is
> this location, from which we read this value, or it means the adress
> location, where we want to store (assign) the new value. ???
> (Note -> the important part) The name of "pointer" also could
> value or adress, but not the (Note: probably adress of ...)
> this pointer indicates to, but but location, where the value of
> stored. ??? equivocality again ???
> > END OF TEXT <
> So, as I understand this tex wants to say, that when for example
> number (value) 4 to valiable a (a = 4), there are actually two
> which are important, which computer stores ...
> one is:
> - that on location a, value 4 is stored ...
> and second:
> - that this specific physical location in memory is "called",
> variable a (by us) ...
However how variables are implemented varies a lot between programming
languages. Python, internally, uses a dictionary for variables. So a
name is simply a lookup key to a dictionary and the value is whatever
against that key.
You can think of an assignment
a = 42
As being almost the same as
Variables['a'] = 42
Where Variables is the Python variable dictionary.
Its not quite as simple as that but not much more complicated either.
However languages like C actually allocate a bit of computer memory
to a variable so that
int a = 42;
actually allocates enough memory to hold an integer and binds the
name 'a' to its address. Then the assinment actually sets that menory
location to hold 42.
> ... which is something, computer should also remember to recognize
> location as "named" as a ("the value of pointer"), beside knowing
> of that location.
This hopefully explains why C has a notion of pointers as well as
because a variable can be defined to hold a memory address. That
can be the address of another variable.
int* b = a
Allocates enough memory to hold an address and binds the name 'b' to
that address, it then fills the address with the address of 'a'.
Python doesn't need to do that since variables are dictionary keys so
all variables are in effect pointers to the real data (which can be of
> Please, tell me, if I am right, ... some variables
> like, a, b, c, d, etc. are fixed, default - meaning that a or b or c
> points to only one, and only one certain physical location in
In languages like C that's true, in Python (and some other languages)
slightly different. To be honest trying to think of variables at that
level of detail
as a beginner is probably just confusing. In my tutorial I use the
of a postal sorting office. The data is what gets put in the boxes and
variables are the labels stuck on the front of the boxes. Data in a
without a label gets thrown in the garbage. That's a pretty accurate
illustration of how Python does things.
Author of the Learn to Program web tutor
More information about the Tutor