c********e 发帖数: 383 | 1 in C i can do,
int i;
int & j = i;
then when i change i's value I will see the change reflected in j as well.
how to do this in python. a quick search around didnt ring any bell.
thx. |
c*****g 发帖数: 119 | 2 use list or other mutable objects.
【在 c********e 的大作中提到】 : in C i can do, : int i; : int & j = i; : then when i change i's value I will see the change reflected in j as well. : how to do this in python. a quick search around didnt ring any bell. : thx.
|
j*****k 发帖数: 1198 | 3 怎么转战场了?Perl里面都有reference, python里面没有?
【在 c********e 的大作中提到】 : in C i can do, : int i; : int & j = i; : then when i change i's value I will see the change reflected in j as well. : how to do this in python. a quick search around didnt ring any bell. : thx.
|
c********e 发帖数: 383 | 4 thx
【在 c*****g 的大作中提到】 : use list or other mutable objects.
|
c********e 发帖数: 383 | 5 picked python to make a quick log parser to do some offline time analysis
and learn something new...
【在 j*****k 的大作中提到】 : 怎么转战场了?Perl里面都有reference, python里面没有?
|
d*******8 发帖数: 3182 | 6 没有
【在 j*****k 的大作中提到】 : 怎么转战场了?Perl里面都有reference, python里面没有?
|
r****t 发帖数: 10904 | 7 python里面全是by reference吧。
【在 d*******8 的大作中提到】 : 没有
|
d*******8 发帖数: 3182 | 8 as i knew, only the elements in list and dict are by reference.
for example:
i = [3, 5]
j = i ==> j is [3, 5]
i[1] = 1 ==> i is [3, 1] and j is [3, 1]
【在 r****t 的大作中提到】 : python里面全是by reference吧。
|
r****t 发帖数: 10904 | 9 所有的attribute也是mutable的。你说的这么几种正好就是所有的immutables |
r****t 发帖数: 10904 | 10 a = [1]
b = a
after this, when you change b[0] to any value, a[0] is also changed
accordingly:
b[0] = 5
assert a[0]==5
b[0] = 'dfadf'
assert a[0]=='dfadf'
这是因为list的元素是mutable的。python全是by reference.
【在 c********e 的大作中提到】 : in C i can do, : int i; : int & j = i; : then when i change i's value I will see the change reflected in j as well. : how to do this in python. a quick search around didnt ring any bell. : thx.
|