View Single Post
Old Dec 8th, 2006, 1:27 AM   #9
Dietrich
Professional Programmer
 
Dietrich's Avatar
 
Join Date: Feb 2005
Posts: 434
Rep Power: 4 Dietrich is on a distinguished road
Quote:
Originally Posted by DaWei View Post
Arevos' point is that it isn't a copy, it's a reference to an immutable value, thus, if you reassign it in the function, you're reassigning the reference to another object, not reassigning the value of the original object. Consider this:
>>> def boogie (a):
...    print a
...    a = 5
...    print a
...    return a
...
>>> a = 10
>>> print boogie (a)
10
5
5
>>> a
10
>>>
In other words, the variable 'a' in the function stays local to the function, as long as variable 'a' is immutable like a number, string or tuple. Immutable parameters are passed by value.
__________________
I looked it up on the Intergnats!
Dietrich is offline   Reply With Quote