two quick questions
Michael Peuser
mpeuser at web.de
Wed Aug 13 03:12:47 EDT 2003
The following examples might clear the more rheoretical elaborations .....
def noUse(a):
a=(4,5,6)
def tricky(a):
a[0]=(7,8,9)
# case 1
x=[1,2,3]
print x
tricky(x)
x=(1,2,3)
# case 2
noUse ([x])
print x
# case 3
tricky([x])
print x
# case 4
y=[x]
tricky (y)
print x
print y[0]
# case 5
tricky(x)
print x
Kindly
Michael Peuser
"Erik Max Francis" <max at alcyone.com> schrieb im Newsbeitrag
news:3F39D89B.A7160172 at alcyone.com...
> Elaine Jackson wrote:
>
> > 1) Does Python have passing-by-reference?
>
> It depends on exactly what you mean by that. In a sense all Python
> objects are passed by reference, but only in the sense that the
> reference is passed by value. (Say that three times fast.)
>
> If you want to get the equivalent of a C++ reference on an immutable
> object, you can do it with containment. Pass the function a mutable
> container containing your object, and then manipulate/change the
> contained object. In the caller's scope, the container will have
> mutated.
>
> > 2) In ordinary parlance, "deep" implies "shallow" but not conversely.
> > In the
> > Python "copy" module (if I understand correctly), the implication goes
> > the other
> > way. Do you find this a nuisance?
>
> I'm not sure what about the copy's modules semantics you're thinking are
> reversed, but the terminology used in the copy module is common in
> computer science. A shallow copy means that the object is copied, but
> it will retain the same references to contained objects; a deep copy
> means that the object is copied, as well as the objects it contains (and
> so on, recursively). A deep copy always does the same thing as a
> shallow copy, and more.
>
> --
> Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
> __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
> / \ I always entertain great hopes.
> \__/ Robert Frost
More information about the Python-list
mailing list