On 08.05.2014 02:35, Ben Finney wrote:
Marko Rauhamaa <ma...@pacujo.net> writes:
[..]
Python, on the other hand, has this behaviour::
foo = [1, 2, 3]
bar = foo # ‘bar’ binds to the value ‘[1, 2, 3]’
assert foo == bar # succeeds
foo[1] = "spam" # ‘foo’ *and* ‘bar’ now == [1, "spam", 3]
[..]
IMHO this is the behavior of having a variable pointing to it's value;
foo to the list and bar to foo.
consider the following:
>>> def f(l):
... l[1] = 'foo'
...
>>> l1 = [1,2,3]
>>> f(l1)
>>> l1
[1, 'foo', 3]
this means, l1 consists of "pointers" to its values.
Otherwise, it's not calling by reference, because
>>> g(l1)
>>> l1
[1, 'foo', 3]
does not change l1. Once again, if I pass an object it behaves like
calling by reference:
>>> class A:
... a = 0
...
>>> a = A()
>>> a.a
0
>>> def h(a1):
... a1.a = 1
...
>>> h(a)
>>> a.a
1
bg,
Johannes
--
Johannes Schneider
Webentwicklung
johannes.schnei...@galileo-press.de
Tel.: +49.228.42150.xxx
Galileo Press GmbH
Rheinwerkallee 4 - 53227 Bonn - Germany
Tel.: +49.228.42.150.0 (Zentrale) .77 (Fax)
http://www.galileo-press.de/
Geschäftsführer: Tomas Wehren, Ralf Kaulisch, Rainer Kaltenecker
HRB 8363 Amtsgericht Bonn
--
https://mail.python.org/mailman/listinfo/python-list