queue for large objects, object references
Josiah Carlson
jcarlson at uci.edu
Wed Mar 31 00:13:43 EST 2004
> Is the data transferred or only a reference?
Everything in Python can be thought of as passed by reference. This
will mean different things to different people, which is why you should
look at these examples.
>>> def funct(i):
... i += 1
...
>>> k = 8
>>> funct(k)
>>> k
8
The integer doesn't get updated, because integers are immutable.
>>> def funct(l):
... l = []
...
>>> k = [1,2,3]
>>> funct(k)
>>> k
[1, 2, 3]
Pointing the name 'l' to a new list object, doesn't change the object
that 'k' points to.
>>> def funct(l):
... l[:] = []
...
>>> k = [4,5,6]
>>> funct(k)
>>> k
[]
The list only gets updated when you actually modify the list pointed to
by the list named 'l'.
There are literally hundreds more examples I could go through. I'll let
you try to figure a few of those out.
- Josiah
More information about the Python-list
mailing list