【转载】图解 Python 深拷贝和浅拷贝

时间:2022-03-20 21:57:08

图解 Python 深拷贝和浅拷贝


var jiathis_config={ data_track_clickback:false, title:"分享从伯乐在线看到的一篇好文章 ", summary:"《图解 Python 深拷贝和浅拷贝》", pic:"http://www.itdaan.com/imgs/4/4/9/7/36/22f575a178ce3574ae24b5a59e4e14ff.jpe", appkey:{ "tsina": 1473879058 }, ralateuid:{ "tsina": 5305630013 }, hideMore:false }


【转载】图解 Python 深拷贝和浅拷贝



        <div id="article-comment" class="dot-box center-align">

                    <a href="http://www.jobbole.com/login?redirect=http://python.jobbole.com/82294/"><button type="button" class="btn btn-non-transparent">登录后评论</button></a>

        <a target="_blank" href="http://www.jobbole.com/register"><button type="button" class="btn btn-primary">新用户注册</button></a>

        <br><br>
        <span>直接登录</span>
        <style type="text/css">.t_login_text{margin:0; padding:0;}.t_login_button{margin:0; padding: 5px 0;}.t_login_button a{margin:0; padding-right:3px; line-height:25px}.t_login_button img{display:inline; border:none;}</style><!-- 使用社交帐号登录 来自 WordPress连接微博 插件 --><span class="connectBox1 t_login_button"><a href="http://python.jobbole.com/wp-content/plugins/wp-connect/login.php?go=weixin&amp;redirect_url=http%3A%2F%2Fpython.jobbole.com%2F82294%2F" title="微信" rel="nofollow"><img src="http://python.jobbole.com/wp-content/plugins/wp-connect/images/login/btn_weixin.png"></a><a href="http://python.jobbole.com/wp-content/plugins/wp-connect/login.php?go=qzone&amp;redirect_url=http%3A%2F%2Fpython.jobbole.com%2F82294%2F" title="QQ" rel="nofollow"><img src="http://python.jobbole.com/wp-content/plugins/wp-connect/images/login/btn_qzone.png"></a><a href="http://python.jobbole.com/wp-content/plugins/wp-connect/login.php?go=sina&amp;redirect_url=http%3A%2F%2Fpython.jobbole.com%2F82294%2F" title="新浪微博" rel="nofollow"><img src="http://python.jobbole.com/wp-content/plugins/wp-connect/images/login/btn_sina.png"></a><a href="http://python.jobbole.com/wp-content/plugins/wp-connect/login.php?go=douban&amp;redirect_url=http%3A%2F%2Fpython.jobbole.com%2F82294%2F" title="豆瓣" rel="nofollow"><img src="http://python.jobbole.com/wp-content/plugins/wp-connect/images/login/btn_douban.png"></a><a href="http://python.jobbole.com/wp-content/plugins/wp-connect/login.php?go=github&amp;redirect_url=http%3A%2F%2Fpython.jobbole.com%2F82294%2F" title="GitHub" rel="nofollow"><img src="http://python.jobbole.com/wp-content/plugins/wp-connect/images/login/btn_github.png"></a></span>        </div>


<div id="comment_list" class="comments">

                <h5 id="comments" class="sub-title"><i class="glyphicon"></i>最新评论</h5>
        <ul class="cmnt-list">

                    <li id="comment-93937" class="comment cmnt odd">

<div class="cmnt-box">
    <div class="cmnt-header">
                        <a href="http://www.jobbole.com/members/3261591503" class="cmnt-img"><img width="37" height="37" src="http://tp1.sinaimg.cn/3261591503/180/0/1" alt=""></a>
            <div class="cmnt-meta">
                <span><a href="http://www.jobbole.com/members/3261591503">商商潘</a><label class="comment_author_data">&nbsp;( <a title="声望值" target="_blank" href="http://www.jobbole.com/members/3261591503/reputation/"><i class="fa fa-graduation-cap"></i> 1</a> · <a title="微博主页" target="_blank" href="http://weibo.com/3261591503"><i class="fa fa-weibo"></i></a>&nbsp; )</label></span>
                <span class="c-title">
                    &nbsp;                    </span>

                <span class="c-date">
                    <a href="http://python.jobbole.com/82294/#comment-93937">2016/07/17</a>
                </span>



            </div>
                </div>
    <div class="cmnt-body">
        <p>
            </p><p>如果元祖变量只包含原子类型对象,则不能深拷贝.</p>

这句纠正一下,不是说法不对,而是在文中放错位置了。

这样的情况下,浅拷贝和深拷贝结果一致,本身就符合浅拷贝和深拷贝的逻辑啊。

        <p></p>
                </div>
                <div class="cmnt-footer">


            <p class="c-like">
                <a title="赞同" alt="赞同" class="93937voteflag  t-up  href-style vote-comment-up  register-user-only   " data-comment-id="93937"><i class="fa fa-thumbs-o-up"></i> <span id="93937voteuptotal"> 赞</span></a>


                <a rel="nofollow" class="comment-reply-link register-user-only" href="http://python.jobbole.com/82294/?replytocom=93937#respond" data-onclick="return addComment.moveForm( &quot;comment-93937&quot;, &quot;93937&quot;, &quot;respond&quot;, &quot;82294&quot; )" aria-label="回复给商商潘">回复 <i class="fa fa-reply"></i></a>
            </p>
        </div>
        </div>
</li>


  • <div class="cmnt-box">
        <div class="cmnt-header">
                            <a href="http://www.jobbole.com/members/q2356814955" class="cmnt-img"><img width="37" height="37" src="http://q.qlogo.cn/qqapp/208656/C215F0A88DBC427D3764FF6B9480C581/100" alt=""></a>
                <div class="cmnt-meta">
                    <span><a href="http://www.jobbole.com/members/q2356814955">watcher</a><label class="comment_author_data">&nbsp;</label></span>
                    <span class="c-title">
                        &nbsp;                    </span>
    
                    <span class="c-date">
                        <a href="http://python.jobbole.com/82294/#comment-94428">2017/03/31</a>
                    </span>
    
    
    
                </div>
                    </div>
        <div class="cmnt-body">
            <p>
                </p><p>深拷贝和浅拷贝中是不是['python','c#', 'javascrip']还掉了一层地址吧,不然这样说不通啊</p>
            <p></p>
                    </div>
                    <div class="cmnt-footer">
    
    
                <p class="c-like">
                    <a title="赞同" alt="赞同" class="94428voteflag  t-up  href-style vote-comment-up  register-user-only   " data-comment-id="94428"><i class="fa fa-thumbs-o-up"></i> <span id="94428voteuptotal"> 赞</span></a>
    
    
                    <a rel="nofollow" class="comment-reply-link register-user-only" href="http://python.jobbole.com/82294/?replytocom=94428#respond" data-onclick="return addComment.moveForm( &quot;comment-94428&quot;, &quot;94428&quot;, &quot;respond&quot;, &quot;82294&quot; )" aria-label="回复给watcher">回复 <i class="fa fa-reply"></i></a>
                </p>
            </div>
            </div>
    </li>
    


    </div>
    


  •                 <!-- BEGIN .post-meta -->
                    <div class="post-meta  no-thumb">
    
                        <p>
                            <span class="numb">0</span>
                            <a class="meta-title" target="_blank" href="http://python.jobbole.com/89060/" title="Python 工匠:编写条件分支代码的技巧">Python 工匠:编写条件分支代码的...</a><br>
                        </p>
    
                    </div>
                    <!-- END .post-meta -->
    
                    <div class="clear"></div>
    
    
    
                    <!-- BEGIN .post-meta -->
                    <div class="post-meta  no-thumb">
    
                        <p>
                            <span class="numb">1</span>
                            <a class="meta-title" target="_blank" href="http://python.jobbole.com/89074/" title="用 Python 编写的 Python 解释器">用 Python 编写的 Python 解释器</a><br>
                        </p>
    
                    </div>
                    <!-- END .post-meta -->
    
                    <div class="clear"></div>
    
                </div></div><div id="tab2" class="tab" style="display: none;"><div class="floated-thumb">
    
                    <!-- BEGIN .post-meta -->
                    <div class="post-meta  no-thumb">
    
                        <p>
                            <span class="numb">0</span>
                            <a class="meta-title" target="_blank" href="http://python.jobbole.com/89041/" title="用 Python 构建一个极小的区块链">用 Python 构建一个极小的区块链</a><br>
                        </p>
    
                    </div>
                    <!-- END .post-meta -->
    
                    <div class="clear"></div>
    
    
    
                    <!-- BEGIN .post-meta -->
                    <div class="post-meta  no-thumb">
    
                        <p>
                            <span class="numb">1</span>
                            <a class="meta-title" target="_blank" href="http://python.jobbole.com/89031/" title="愉快地迁移到 Python 3">愉快地迁移到 Python 3</a><br>
                        </p>
    
                    </div>
                    <!-- END .post-meta -->
    
                    <div class="clear"></div>
    
    
    
                    <!-- BEGIN .post-meta -->
                    <div class="post-meta  no-thumb">
    
                        <p>
                            <span class="numb">2</span>
                            <a class="meta-title" target="_blank" href="http://python.jobbole.com/89046/" title="5 种使用 Python 代码轻松实现数据可视化的方法">5 种使用 Python 代码轻松实现数...</a><br>
                        </p>
    
                    </div>
                    <!-- END .post-meta -->
    
                    <div class="clear"></div>
    
    
    
                    <!-- BEGIN .post-meta -->
                    <div class="post-meta  no-thumb">
    
                        <p>
                            <span class="numb">3</span>
                            <a class="meta-title" target="_blank" href="http://python.jobbole.com/89060/" title="Python 工匠:编写条件分支代码的技巧">Python 工匠:编写条件分支代码的...</a><br>
                        </p>
    
                    </div>
                    <!-- END .post-meta -->
    
                    <div class="clear"></div>
    
    
    
                    <!-- BEGIN .post-meta -->
                    <div class="post-meta  no-thumb">
    
                        <p>
                            <span class="numb">4</span>
                            <a class="meta-title" target="_blank" href="http://python.jobbole.com/89074/" title="用 Python 编写的 Python 解释器">用 Python 编写的 Python 解释器</a><br>
                        </p>
    
                    </div>
                    <!-- END .post-meta -->
    
                    <div class="clear"></div>
    
                </div></div><div id="tab3" class="tab" style="display: none;"><p><a href="http://python.jobbole.com/tag/api/" class="tag-link-1197 tag-link-position-1" title="5个话题" style="font-size: 8.6222222222222px;">API</a>
    

    beautifulsoup
    Celery
    Django
    featuredpost
    Flask
    GDB
    gevent
    GIL
    import
    itertools
    Linux
    logging
    matplotlib
    MongoDB
    MySQL
    Nginx
    NLP
    NumPy
    oop
    OpenCV
    ORM
    Pandas
    pyenv
    pyGame
    Pyspider
    Python
    python源码
    R
    restful
    Scikit-Learn
    Scrapy
    setuptools
    Socket
    Spark
    SQLAlchemy
    tensorflow
    Tornado
    Vim
    virtualenv
    web
    web开发
    Web服务器
    werkzeug
    WSGI
    XML
    作用域
    元类
    决策树
    函数
    函数式编程
    列表
    协程
    图像处理
    垃圾回收
    多线程
    多进程
    字典
    字符串
    字符编码
    安全
    并发
    并行
    异步
    微信
    性能
    性能分析
    描述符
    教程
    数据分析
    数据可视化
    数据挖掘
    数据科学
    数据结构
    数据结构与算法
    机器学习
    标准库
    树形结构
    正则表达式
    深度学习
    游戏编程
    爬虫
    生成器
    神经网络
    算法

    线性回归
    线程
    编码
    网络爬虫
    网页爬虫
    聚类
    装饰器
    解释器
    贝叶斯
    迭代器
    遗传算法
    闭包
    面向对象
    面试

    【转载】图解 Python 深拷贝和浅拷贝




    Python工具资源
    更多资源 »



                    <div class="floated-thumb">
                        <div class="post-thumb">
                            <a target="_blank" href="http://hao.jobbole.com/tryton/?utm_source=python.jobbole.com&amp;utm_medium=sidebar-resources" title="Tryton:一个通用商务框架"><img src="http://jbcdn1.b0.upaiyun.com/2017/01/fbce31ffc19ced1422abbb0a860c5ab7.png" alt="" width="50" height="50"></a>
                        </div>
                        <div class="post-meta">
                            <p>
                                <a class="meta-title" target="_blank" href="http://hao.jobbole.com/tryton/?utm_source=python.jobbole.com&amp;utm_medium=sidebar-resources" title="Tryton:一个通用商务框架">Tryton:一个通用商务框架</a><br>
                                <a href="http://hao.jobbole.com/category/python-tools/python-misc/" rel="category tag">杂项</a>
                            </p>
                        </div>
                        <div class="clear"></div>
                    </div>
    
                    <div class="floated-thumb">
                        <div class="post-thumb">
                            <a target="_blank" href="http://hao.jobbole.com/nltk/?utm_source=python.jobbole.com&amp;utm_medium=sidebar-resources" title="NLTK:一个先进的用来处理自然语言数据的Python程序。"><img src="http://jbcdn1.b0.upaiyun.com/2016/12/0384e39ce19622237039c4a86febccc9.png" alt="" width="50" height="50"></a>
                        </div>
                        <div class="post-meta">
                            <p>
                                <a class="meta-title" target="_blank" href="http://hao.jobbole.com/nltk/?utm_source=python.jobbole.com&amp;utm_medium=sidebar-resources" title="NLTK:一个先进的用来处理自然语言数据的Python程序。">NLTK:一个先进的用来处理自然语言数据的Python程序。</a><br>
                                <a href="http://hao.jobbole.com/category/python-tools/python-natural-lang/" rel="category tag">自然语言处理</a> · <a target="_blank" href="http://hao.jobbole.com/nltk/#comments"><i class="fa fa-comments-o"></i> 3</a>
                            </p>
                        </div>
                        <div class="clear"></div>
                    </div>
    
                    <div class="floated-thumb">
                        <div class="post-thumb">
                            <a target="_blank" href="http://hao.jobbole.com/pymc/?utm_source=python.jobbole.com&amp;utm_medium=sidebar-resources" title="PyMC:马尔科夫链蒙特卡洛采样工具"><img src="http://jbcdn1.b0.upaiyun.com/2016/12/bf6677dba678925802f3f1e76ec760c3.png" alt="" width="50" height="50"></a>
                        </div>
                        <div class="post-meta">
                            <p>
                                <a class="meta-title" target="_blank" href="http://hao.jobbole.com/pymc/?utm_source=python.jobbole.com&amp;utm_medium=sidebar-resources" title="PyMC:马尔科夫链蒙特卡洛采样工具">PyMC:马尔科夫链蒙特卡洛采样工具</a><br>
                                <a href="http://hao.jobbole.com/category/python-tools/python-science-data-analysis/" rel="category tag">科学计算与分析</a>
                            </p>
                        </div>
                        <div class="clear"></div>
                    </div>
    
                    <div class="floated-thumb">
                        <div class="post-thumb">
                            <a target="_blank" href="http://hao.jobbole.com/statsmodels/?utm_source=python.jobbole.com&amp;utm_medium=sidebar-resources" title="statsmodels:统计建模和计量经济学"><img src="http://jbcdn1.b0.upaiyun.com/2016/12/e88a9784e92acb81d2f3c8331493e004.png" alt="" width="50" height="50"></a>
                        </div>
                        <div class="post-meta">
                            <p>
                                <a class="meta-title" target="_blank" href="http://hao.jobbole.com/statsmodels/?utm_source=python.jobbole.com&amp;utm_medium=sidebar-resources" title="statsmodels:统计建模和计量经济学">statsmodels:统计建模和计量经济学</a><br>
                                <a href="http://hao.jobbole.com/category/python-tools/python-science-data-analysis/" rel="category tag">科学计算与分析</a>
                            </p>
                        </div>
                        <div class="clear"></div>
                    </div>
    
                    <div class="floated-thumb">
                        <div class="post-thumb">
                            <a target="_blank" href="http://hao.jobbole.com/pylearn2/?utm_source=python.jobbole.com&amp;utm_medium=sidebar-resources" title="Pylearn2:一个基于Theano的机器学习库"><img src="http://jbcdn1.b0.upaiyun.com/2016/12/660abdb1c0391cfc738b3266106119c9.png" alt="" width="50" height="50"></a>
                        </div>
                        <div class="post-meta">
                            <p>
                                <a class="meta-title" target="_blank" href="http://hao.jobbole.com/pylearn2/?utm_source=python.jobbole.com&amp;utm_medium=sidebar-resources" title="Pylearn2:一个基于Theano的机器学习库">Pylearn2:一个基于Theano的机器学习库</a><br>
                                <a href="http://hao.jobbole.com/category/python-tools/python-machine-learning/" rel="category tag">机器学习</a> · <a target="_blank" href="http://hao.jobbole.com/pylearn2/#comments"><i class="fa fa-comments-o"></i> 1</a>
                            </p>
                        </div>
                        <div class="clear"></div>
                    </div>
                                </div>
            </div>
    
    <!-- BEGIN .container -->
    <div class="container">
    
        <!-- BEGIN .grid-2 -->
        <div class="grid-2">
    
    
        </div>
        <!-- END .grid-2 -->
    
        <!-- BEGIN .grid-2 -->
        <div class="grid-2">
    
    
        </div>
        <!-- END .grid-2 -->
    
        <div class="clear"></div>
    
    </div>
    <!-- END .container -->