python byRef 复制

python byRef 复制,第1张

python byRef //复制

不,结果应为1。

赋值运算符(

=
)视为参考的赋值。

a = 1 #a references the integer object 1b = a #b and a reference the same objecta = 2 #a now references a new object (2)print b # prints 1 because you changed what a references, not b

同时,这整个的区别真的是最重要的 可变 对象,如

lists
,而不是 一成不变的 状物体
int
float
tuple

现在考虑以下代码:

a=[]  #a references a mutable objectb=a   #b references the same mutable objectb.append(1)  #change b a little bitprint a # [1] -- because a and b still reference the same object         #        which was changed via b.


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5664009.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存