美文网首页
2018-08-19

2018-08-19

作者: 白s圣诞节 | 来源:发表于2018-08-19 19:49 被阅读0次

    一、==和is的区别:

    *==

    比较两个对象是否相等

    a = [11,22,33]
    b = a
    a == b
    True
    a = 23
    b = a 
    a == b
    True
    
    a = [11,22,33]
    b = [11,22,33]
    a == b
    True
    a = 24
    b = 24
    a == b
    True
    

    *is

    比较两个引用是否指向了同一个对象(引用比较)(大于256就是false)

    a = 180
    b = 180
    a is b
    True
    a = 257
    b = 257
    a is b
    False
    
    a = 257
    b = a
    a is b
    True
    a = 180
    b = a
    a is b
    True
    
    a = [11,22]
    b = [11,22]
    a is b
    False
    a = [11,22]
    b = a
    a is b
    True
    

    二、深拷贝、浅拷贝

    *浅拷贝:(拷贝了引用,并没有拷贝内容)

    image.png
    image.png

    *深拷贝:(对于一个对象所有层次的拷贝)

    image.png
    image.png

    相关文章

      网友评论

          本文标题:2018-08-19

          本文链接:https://www.haomeiwen.com/subject/zixhiftx.html