<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 中没有元组理解?

      时间:2023-09-01

          <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 中没有元组理解?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:元组 (a,b)=(b,a) 中的成员交换如何在内部工作? 下一篇:如何从元组列表中提取第 n 个元素

                相关文章

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

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