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

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

      为什么 Python 中没有元组理解?

      Why is there no tuple comprehension in Python?(为什么 Python 中没有元组理解?)

          <tbody id='kLyVG'></tbody>
        • <legend id='kLyVG'><style id='kLyVG'><dir id='kLyVG'><q id='kLyVG'></q></dir></style></legend>

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

              <bdo id='kLyVG'></bdo><ul id='kLyVG'></ul>

              1. <small id='kLyVG'></small><noframes id='kLyVG'>

                本文介绍了为什么 Python 中没有元组理解?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                众所周知,有列表推导式,比如

                As we all know, there's list comprehension, like

                [i for i in [1, 2, 3, 4]]
                

                还有字典理解,比如

                {i:j for i, j in {1: 'a', 2: 'b'}.items()}
                

                但是

                (i for i in (1, 2, 3))
                

                将在生成器中结束,而不是 tuple 理解.这是为什么呢?

                will end up in a generator, not a tuple comprehension. Why is that?

                我的猜测是 tuple 是不可变的,但这似乎不是答案.

                My guess is that a tuple is immutable, but this does not seem to be the answer.

                推荐答案

                你可以使用生成器表达式:

                You can use a generator expression:

                tuple(i for i in (1, 2, 3))
                

                但括号已经用于...生成器表达式.

                but parentheses were already taken for … generator expressions.

                这篇关于为什么 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 与否?)

                <small id='6CtAe'></small><noframes id='6CtAe'>

                1. <legend id='6CtAe'><style id='6CtAe'><dir id='6CtAe'><q id='6CtAe'></q></dir></style></legend>
                2. <tfoot id='6CtAe'></tfoot>
                    <bdo id='6CtAe'></bdo><ul id='6CtAe'></ul>

                      <tbody id='6CtAe'></tbody>

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