<br><br><div><span class="gmail_quote">On 2/3/06, <b class="gmail_sendername">Kent Johnson</b> <<a href="mailto:kent37@tds.net" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">kent37@tds.net</a>> wrote:
</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
> On 2/3/06, Chris or Leslie Smith <<a href="mailto:smiles@worksmail.net" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">smiles@worksmail.net</a>> wrote:<br>>>Others could give you a really good answer. I am a BASIC/FORTRAN writer
<br>>>myself, and getting used to the *object* orientation of python took a little
<br>>>while, but after you get the hang of it, it's not bad. In BASIC you think of<br>>>variables *containing* things, so when you say l=2 and a=l you think of two<br>>>variables each containing the (what happens to be) the same thing. In
<br>>>python, however, mutable objects (like lists) are *pointed to* by the<br>>>variable name. so the 'l=range(3)' above tells python to create a list and<br>>>point the variable name 'l' at it. Then when you say 'a=l' you are telling
<br>>>it to point 'a' at the same thing as 'l'--one object (the list); two<br>>>references to it.<br><br>You definitely have to stop thinking of variables as containers. They<br>are pointers or references to values. Another way to think of this is
<br>that variables are names for things. You may call me Kent, someone else<br>might call me Mr. Johnson or Dad, but if I get a haircut, Kent, Mr.<br>Johnson and Dad all have shorter hair because all three names refer to
<br>
the same person.<br><br>Python works the same way. Assignment binds a name to a value. So if I say<br> lst = [0, 1, 2]<br>I have bound the name 'lst' to a particular list whose value, at the<br>moment, is [0, 1, 2]. If I then assign
<br> a = lst<br>this binds the name 'a' to the same value (the list) that 'lst' is bound<br>to. If I change the bound list, you will see the change whether you<br>access the list through the name 'a' or the name 'lst'.
<br>
<br>Kent</blockquote><div><br><br>Kent that's a perfectly understandable and easy to grasp analogy. But it stays just an analogy ;-)<br>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
<br><br>My question might be summed up to:<br>When would I have need of this? Or why do I want it? Where is the benefit?<br><br>When I look at this:<br><br>for x in range(3):<br><br>I know it is shorthand for something like (not exactly but it serves its purpose as an example):
<br><br>x = 0<br>while x<=3 do:<br> x = x +1<br><br>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.
<br>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)).<br><br>Oh and tell me to shut up and just accept it if you want to ;-)
</div></div>