<legend id='QKce3'><style id='QKce3'><dir id='QKce3'><q id='QKce3'></q></dir></style></legend>

    • <bdo id='QKce3'></bdo><ul id='QKce3'></ul>
      <tfoot id='QKce3'></tfoot>

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

    2. <small id='QKce3'></small><noframes id='QKce3'>

      为什么 python 字符串和元组是不可变的?

      Why are python strings and tuples are made immutable?(为什么 python 字符串和元组是不可变的?)
        <bdo id='HacM9'></bdo><ul id='HacM9'></ul>
          <tbody id='HacM9'></tbody>

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

              <tfoot id='HacM9'></tfoot>

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

              <legend id='HacM9'><style id='HacM9'><dir id='HacM9'><q id='HacM9'></q></dir></style></legend>
                本文介绍了为什么 python 字符串和元组是不可变的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我不确定为什么字符串和元组是不可变的;使它们不可变的优点和缺点是什么?

                I am not sure why strings and tuples were made to be immutable; what are the advantages and disadvantage of making them immutable?

                推荐答案

                一个是性能:知道一个字符串是不可变的,因此很容易在施工时布置——固定不变的存储要求.这也是其中之一区分的原因元组和列表.这也允许安全重用字符串的实现对象.例如,CPython实现使用预分配单字符串的对象,并且通常会返回原件用于字符串操作的字符串不会改变内容.

                One is performance: knowing that a string is immutable makes it easy to lay it out at construction time — fixed and unchanging storage requirements. This is also one of the reasons for the distinction between tuples and lists. This also allows the implementation to safely reuse string objects. For example, the CPython implemenation uses pre-allocated objects for single-character strings, and usually returns the original string for string operations that doesn’t change the content.

                另一个是Python中的字符串被认为是基本的";作为数字.再多的活动也不会将值 8 更改为其他值,在 Python 中,没有多少活动将字符串八"更改为还有什么.

                The other is that strings in Python are considered as "elemental" as numbers. No amount of activity will change the value 8 to anything else, and in Python, no amount of activity will change the string "eight" to anything else.

                https://web.archive.org/web/20201031092707/http://effbot.org/pyfaq/why-are-python-strings-immutable.htm

                这篇关于为什么 python 字符串和元组是不可变的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                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 与否?)

                    • <bdo id='9bF1a'></bdo><ul id='9bF1a'></ul>
                    • <small id='9bF1a'></small><noframes id='9bF1a'>

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

                        • <legend id='9bF1a'><style id='9bF1a'><dir id='9bF1a'><q id='9bF1a'></q></dir></style></legend>
                            <tbody id='9bF1a'></tbody>
                        • <tfoot id='9bF1a'></tfoot>