您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

python byRef //复制

python byRef //复制

不,结果应为1。

将赋值运算符(=)视为参考的赋值。

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

同时,这整个的区别真的是最重要的 可变 对象,如lists,而不是 一成不变的 状物体intfloattuple

现在考虑以下代码

a=[]  #a references a mutable object
b=a   #b references the same mutable object
b.append(1)  #change b a little bit
print a # [1] -- because a and b still reference the same object 
        #        which was changed via b.
python 2022/1/1 18:51:41 有389人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶