On 2/3/06, Kent Johnson <[EMAIL PROTECTED]> wrote:
> On 2/3/06, Chris or Leslie Smith <[EMAIL PROTECTED]> wrote:
>>Others could give you a really good answer. I am a BASIC/FORTRAN writer
>>myself, and getting used to the *object* orientation of python took a little
>>while, but after you get the hang of it, it's not bad. In BASIC you think of
>>variables *containing* things, so when you say l=2 and a=l you think of two
>>variables each containing the (what happens to be) the same thing. In
>>python, however, mutable objects (like lists) are *pointed to* by the
>>variable name. so the 'l=range(3)' above tells python to create a list and
>>point the variable name 'l' at it. Then when you say 'a=l' you are telling
>>it to point 'a' at the same thing as 'l'--one object (the list); two
>>references to it.

You definitely have to stop thinking of variables as containers. They
are pointers or references to values. Another way to think of this is
that variables are names for things. You may call me Kent, someone else
might call me Mr. Johnson or Dad, but if I get a haircut, Kent, Mr.
Johnson and Dad all have shorter hair because all three names refer to
the same person.

Python works the same way. Assignment binds a name to a value. So if I say
   lst = [0, 1, 2]
I have bound the name 'lst' to a particular list whose value, at the
moment, is [0, 1, 2]. If I then assign
   a = lst
this binds the name 'a' to the same value (the list) that 'lst' is bound
to. If I change the bound list, you will see the change whether you
access the list through the name 'a' or the name 'lst'.

Kent


Kent that's a perfectly understandable and easy to grasp analogy. But it stays just an analogy ;-)
Thing is.  We people consist of more than a 1st name to identify ourself. It is 1st name, last name, country, place of birth, town you now live in, street, postal code, number of the house, date of birth and in case of twins or triplets even the time of birth and maybe a bunch more details. But coding is not IRL and isn't a reflection of it either. Coding is alot easier bacause it does not require that 2 variables need to be linked. I have been coding with the knowledge A is A and A is never B. Not even if they contain the same content but they can have the content copied from 1 to another :-P

My question might be summed up to:
When would I have need of this?  Or why do I want it? Where is the benefit?

When I look at this:

for x in range(3):

I know it is shorthand for something like (not exactly but it serves its purpose as an example):

x = 0
while x<=3 do:
   x = x +1

And I understand why it is done this way: it makes code shorter AND it is even easier to read: a win-win situation. And the same goes for alot of other things in Python.
But this assignment sort of puzzles me to why it's done like this (maybe cuz I am not used to it and can not see beyond my own experience in coding (having a blind spot or something like that)).

Oh and tell me to shut up and just accept it if you want to ;-)
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to