<small id='lnzM7'></small><noframes id='lnzM7'>

  • <legend id='lnzM7'><style id='lnzM7'><dir id='lnzM7'><q id='lnzM7'></q></dir></style></legend>
    • <bdo id='lnzM7'></bdo><ul id='lnzM7'></ul>

    1. <i id='lnzM7'><tr id='lnzM7'><dt id='lnzM7'><q id='lnzM7'><span id='lnzM7'><b id='lnzM7'><form id='lnzM7'><ins id='lnzM7'></ins><ul id='lnzM7'></ul><sub id='lnzM7'></sub></form><legend id='lnzM7'></legend><bdo id='lnzM7'><pre id='lnzM7'><center id='lnzM7'></center></pre></bdo></b><th id='lnzM7'></th></span></q></dt></tr></i><div id='lnzM7'><tfoot id='lnzM7'></tfoot><dl id='lnzM7'><fieldset id='lnzM7'></fieldset></dl></div>
      <tfoot id='lnzM7'></tfoot>

      1. 尽管元组是不可变的,但它们以交互模式存储在不同的地址中.为什么?

        Even though tuples are immutable, they are stored in different addresses in interactive mode. Why?(尽管元组是不可变的,但它们以交互模式存储在不同的地址中.为什么?)
            <tbody id='kobR7'></tbody>

          <small id='kobR7'></small><noframes id='kobR7'>

          1. <tfoot id='kobR7'></tfoot><legend id='kobR7'><style id='kobR7'><dir id='kobR7'><q id='kobR7'></q></dir></style></legend>
            <i id='kobR7'><tr id='kobR7'><dt id='kobR7'><q id='kobR7'><span id='kobR7'><b id='kobR7'><form id='kobR7'><ins id='kobR7'></ins><ul id='kobR7'></ul><sub id='kobR7'></sub></form><legend id='kobR7'></legend><bdo id='kobR7'><pre id='kobR7'><center id='kobR7'></center></pre></bdo></b><th id='kobR7'></th></span></q></dt></tr></i><div id='kobR7'><tfoot id='kobR7'></tfoot><dl id='kobR7'><fieldset id='kobR7'></fieldset></dl></div>
                <bdo id='kobR7'></bdo><ul id='kobR7'></ul>
                • 本文介绍了尽管元组是不可变的,但它们以交互模式存储在不同的地址中.为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  t = (1,2,3)
                  t1 = (1,2,3)
                  print(id(t))
                  print(id(t1))
                  

                  以上代码行在 Python 中的脚本模式下给出了相同的地址,但在交互模式下它输出不同的地址.谁能解释一下这是什么原因?

                  The above lines of code gives the same addresses in script mode in Python, but in interactive mode it outputs different addresses. Can anyone explain the reason for this?

                  推荐答案

                  在编译脚本时,编译器可以搜索所有等价的元组并生成代码以对所有元组使用相同的引用.

                  When the script is being compiled, the compiler can search for all the equivalent tuples and generate code to use the same reference for all of them.

                  但在交互模式下,它需要保留所有元组的缓存,以便它可以搜索先前的等效元组并返回对它的引用,而不是每次都创建一个新元组.交互式解释器不这样做.

                  But in interactive mode, it would need to keep a cache of all tuples so it could search for a previous equivalent tuple and return a reference to it, rather than creating a new tuple each time. The interactive interpreter doesn't do this.

                  如果将两个变量分配在同一行,实际上会得到相同的元组.

                  If you assign both variables on the same line, you actually get the same tuple.

                  t = (1, 2, 3); t1 = (1, 2, 3)
                  

                  这大概是因为它为每个输入运行编译器,所以它可以做完整的分析和优化.

                  This is presumably because it's running the compiler for each input, so it can do the full analysis and optimization.

                  这篇关于尽管元组是不可变的,但它们以交互模式存储在不同的地址中.为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Initialize Multiple Numpy Arrays (Multiple Assignment) - Like MATLAB deal()(初始化多个 Numpy 数组(多重赋值) - 像 MATLAB deal())
                  How to extend Python class init(如何扩展 Python 类初始化)
                  What#39;s the difference between dict() and {}?(dict() 和 {} 有什么区别?)
                  What is a wrapper_descriptor, and why is Foo.__init__() one in this case?(什么是 wrapper_descriptor,为什么 Foo.__init__() 在这种情况下是其中之一?)
                  Initialize list with same bool value(使用相同的布尔值初始化列表)
                  setattr with kwargs, pythonic or not?(setattr 与 kwargs,pythonic 与否?)
                    <i id='9L2Lm'><tr id='9L2Lm'><dt id='9L2Lm'><q id='9L2Lm'><span id='9L2Lm'><b id='9L2Lm'><form id='9L2Lm'><ins id='9L2Lm'></ins><ul id='9L2Lm'></ul><sub id='9L2Lm'></sub></form><legend id='9L2Lm'></legend><bdo id='9L2Lm'><pre id='9L2Lm'><center id='9L2Lm'></center></pre></bdo></b><th id='9L2Lm'></th></span></q></dt></tr></i><div id='9L2Lm'><tfoot id='9L2Lm'></tfoot><dl id='9L2Lm'><fieldset id='9L2Lm'></fieldset></dl></div>

                    <legend id='9L2Lm'><style id='9L2Lm'><dir id='9L2Lm'><q id='9L2Lm'></q></dir></style></legend>

                    <small id='9L2Lm'></small><noframes id='9L2Lm'>

                      <tbody id='9L2Lm'></tbody>
                    <tfoot id='9L2Lm'></tfoot>
                      <bdo id='9L2Lm'></bdo><ul id='9L2Lm'></ul>