关闭

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

161人阅读 评论(0) 收藏 举报
分类:
#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']]

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:91343次
    • 积分:2930
    • 等级:
    • 排名:第12493名
    • 原创:165篇
    • 转载:108篇
    • 译文:30篇
    • 评论:1条
    文章分类
    最新评论