zoukankan      html  css  js  c++  java
  • python 基础之深浅拷贝

    深浅拷贝

    s=[[1,2],'fgfgf','cx']
    s3=s.copy()
    print(s)
    print(s3)
    

      测试

    D:pythonpython.exe D:/untitled/dir/for.py
    [[1, 2], 'fgfgf', 'cx']
    [[1, 2], 'fgfgf', 'cx']
    
    Process finished with exit code 0
    

      浅拷贝之修改

    s=[[1,2],'fgfgf','cx']
    s3=s.copy()
    print(s3)
    s3[1]='chhgghg'
    print(s)
    print(s3)
    

      测试

    D:pythonpython.exe D:/untitled/dir/for.py
    [[1, 2], 'fgfgf', 'cx']
    [[1, 2], 'fgfgf', 'cx']
    [[1, 2], 'chhgghg', 'cx']
    
    Process finished with exit code 0
    

      浅拷贝之修改列表

    s=[[1,2],'fgfgf','cx']
    s3=s.copy()
    print(s3)
    s3[0][1]='chhgghg'
    print(s)
    print(s3)
    

      测试

    D:pythonpython.exe D:/untitled/dir/for.py
    [[1, 2], 'fgfgf', 'cx']
    [[1, 'chhgghg'], 'fgfgf', 'cx']
    [[1, 'chhgghg'], 'fgfgf', 'cx']
    
    Process finished with exit code 0
    

      浅拷贝是复制一层

    深拷贝

    haha = ['cx',123,[15000,9000]]
    wit = copy.deepcopy(haha)
    wit[0] = 'cd'
    wit[1] = 6666
    wit[2][1] = 1999
    print(wit)
    print(haha)
    

      测试

    D:pythonpython.exe D:/untitled/dir/for.py
    [[1, 2], 'fgfgf', 'cx']
    [[1, 'chhgghg'], 'fgfgf', 'cx']
    [[1, 'chhgghg'], 'fgfgf', 'cx']
    ['cd', 6666, [15000, 1999]]
    ['cx', 123, [15000, 9000]]
    

      

    草都可以从石头缝隙中长出来更可况你呢
  • 相关阅读:
    Java中的List转换成JSON报错(一)
    关于侦听的注册
    TCMalloc小记
    ocp|ocm考证系列文章
    开源HTML5 APP开发神器CanTK发布
    实例级别的回滚
    MySQL查询所有数据库表出错
    java.lang.ArrayIndexOutOfBoundsException
    如何修改64位Eclipse中的代码字体大小
    gpt 分区容量错误
  • 原文地址:https://www.cnblogs.com/rdchenxi/p/11127570.html
Copyright © 2011-2022 走看看