At 06:35 PM 5/20/2008 -0700, Warren Sande wrote:

>Putting aside the "pass-by-X" question, a beginner asks:
>
>"If I  do    A = (something)   then   B = A    then I change A, does B also 
>change?"
>
>And the answer, again, is "It depends."  For mutable types, yes, for immutable 
>types, no.  And that's a sticky thing to get into for a beginner who is just 
>learning what variables (names) are about.

At this point, I would immediately stop using vague words like "change", and 
try to find words with a more precise meaning, like "re-bind" and "modify".  
"Re-assign" would be another possibility, but I see that "re-bind" is commonly 
used in Python texts.  Also, it is a less common word than re-assign, so less 
likely to have other meanings.  "Mutate" might be better than "modify" for the 
same reason.

Long before any discussion of parameter passing, students should have a firm 
grasp of how variables work in Python, including the concepts of mutability and 
rebinding.  This is the model and terminology I suggest: 

   variable:(name, pointer) --> object:(type, value, address)

Other than the word "value", I don't see any confusion with any of these terms. 
 I haven't heard any suggestions for a better simple model.

With this model in mind, the simple answer to the student's question is - "It 
depends on whether you are modifying the object of variable A, or re-binding A 
to some other object.

-- Dave




_______________________________________________
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig

Reply via email to