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

      

    草都可以从石头缝隙中长出来更可况你呢
  • 相关阅读:
    join()方法的使用
    synchronized关键字
    voliatle关键字
    一.线程概述
    NIO demo
    同步阻塞I/O
    Ubuntu16.04.1 安装Nginx
    垃圾收集
    如何从头开始安装 wordpress
    centos 6 安装 gnu c++ 等开发工具
  • 原文地址:https://www.cnblogs.com/rdchenxi/p/11127570.html
Copyright © 2011-2022 走看看