value equality vs. object equality, aliasing, list is mutable DEMO

转载 2015年07月09日 10:13:57
#quote from MIT 'introduction to computation and programming using python, Revised'
Techs = ['MIT', 'CalTech']

Ivys = ['Harvard', 'Yale', 'Brown']

univ = [Techs, Ivys]

univ1 = [['MIT', 'CalTech'], ['Harvard', 'Yale', 'Brown']]

print univ
[['MIT', 'CalTech'], ['Harvard', 'Yale', 'Brown']]

print univ1
[['MIT', 'CalTech'], ['Harvard', 'Yale', 'Brown']]

print univ == univ1
True

print id(univ), id(univ1)
121487688 122964408

print id(univ) == id(univ1)
False

Techs.append('xxx')

print univ
[['MIT', 'CalTech', 'xxx'], ['Harvard', 'Yale', 'Brown']]

print univ1
[['MIT', 'CalTech'], ['Harvard', 'Yale', 'Brown']]

Ivys[0] = 'kkk'

print univ
[['MIT', 'CalTech', 'xxx'], ['kkk', 'Yale', 'Brown']]

print univ1
[['MIT', 'CalTech'], ['Harvard', 'Yale', 'Brown']]

内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:value equality vs. object equality, aliasing, list is mutable DEMO
举报原因:
原因补充:

(最多只允许输入30个字)