wasm-demo/demo/ermis-f/python_m/cur/0870

84 lines
2.6 KiB
Plaintext

From: tismer at appliedbiometrics.com (Christian Tismer)
Date: Fri, 23 Apr 1999 14:36:56 +0200
Subject: Pointers to variables
References: <19990422121403.A279051@vislab.epa.gov> <wkk8v4ef5e.fsf@turangalila.harmonixmusic.com> <19990423080721.A344578@vislab.epa.gov>
Message-ID: <37206968.C1E548BD@appliedbiometrics.com>
Content-Length: 2300
X-UID: 870
Randall Hopper wrote:
...
[you are beginning to understand the concept]
...
> but this one doesn't:
>
> (3) min = 0
> max = 0
> for ( var, val ) in [( min, 1 ), ( max, 100 )]:
> var = val
>
> So basically this is just a little asymmetry in the language. Putting a
> variable in a list/tuple (valueof(var)) performs a shallow copy rather than
> a deep copy.
>
> Does this sound about right?
Not completely. There is no asymmetry if you take the right
position. I'll try to adjust jour sight a little :-)
There is sometimes a little confusion since people talk
of Python, passing "variables" by "reference", which is
wrong. Python passes objects by reference, but no variables
at all, in the sense of a "C" variable.
(You might find some more about this in the tutor archive).
It is better to think of labels, sticked to boxes which
are the objects.
By "min = 0", you stick the label "min" to the object "0".
By "var = val", you pick the object which has the label
"val", and stick label "var" to it as well.
While passign the values around between the lables, Python
indeed uses reverences to the objects, although in this
example, it makes no difference, since the values of
unchangeable (immutable) objects like numbers cannot be changed.
You will recognze the difference, if you use different objects
like lists. In
a = [1, 2, 3]
I've put a label "a" to a list object with three numbers.
Now I can use a as a handle to the list, it gives me a reference
to the object which I now can change, like
a[1] = "howdy", which reads now
>>> a
[1, 'howdy', 3]
>>>
Now you will understand that I did not change the "variable a".
I also did not change the "label a", but I modified the list
object where a was my handle.
while 1:
if vanished("asymmetry"):
break
think_again() #:-)
Hope this helps - chris
--
Christian Tismer :^) <mailto:tismer at appliedbiometrics.com>
Applied Biometrics GmbH : Have a break! Take a ride on Python's
Kaiserin-Augusta-Allee 101 : *Starship* http://starship.python.net
10553 Berlin : PGP key -> http://wwwkeys.pgp.net
PGP Fingerprint E182 71C7 1A9D 66E9 9D15 D3CC D4D7 93E2 1FAE F6DF
we're tired of banana software - shipped green, ripens at home