Pass by reference ?

Daniel Berlin dan at cgsoftware.com
Wed Apr 5 19:48:27 EDT 2000


> 
>    def Nuke(w):
>      print w,
>      w=None
>      print w

Sorry, this function is not a good demonstration.
w is a reference to whatever is passed in.
Then you are making w a reference to None.
What you should try is w.append(5), or something

Try thusly:
def Appender(w):
	print w
	w.append(5)
	print w
Now, let's call this:

x=[]
Appender(x)

You'll see:
[]
[5]
Then, if you print x, you'll see:
[5]

Thus, we passed it by reference, because it modified the original.
HTH,
Dan
> This behavior meets the classical definition of "Pass By Value".

Bad example.

> 
> What other tests have I omitted, and what do they yield?
See above.

> 
> 
> -BobC
> 
> -- 
> http://www.python.org/mailman/listinfo/python-list
> 





More information about the Python-list mailing list