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]]
    

      

    草都可以从石头缝隙中长出来更可况你呢
  • 相关阅读:
    第01组 Beta版本演示
    2019 SDN上机第7次作业
    第01组 Beta冲刺(4/4)
    系统综合实践第6次作业
    系统综合实践第5次作业
    系统综合实践第4次作业
    系统综合实践第3次作业
    系统综合实践第2次作业
    系统综合实践第1次作业
    软工实践个人总结
  • 原文地址:https://www.cnblogs.com/rdchenxi/p/11127570.html
Copyright © 2011-2022 走看看