• <bdo id='3SSHQ'></bdo><ul id='3SSHQ'></ul>
    <tfoot id='3SSHQ'></tfoot>

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

      1. <legend id='3SSHQ'><style id='3SSHQ'><dir id='3SSHQ'><q id='3SSHQ'></q></dir></style></legend>

        解压元组的pythonic方法是什么?

        What is the pythonic way to unpack tuples?(解压元组的pythonic方法是什么?)
            <tfoot id='UcHUF'></tfoot>

                <tbody id='UcHUF'></tbody>

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

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

                • <legend id='UcHUF'><style id='UcHUF'><dir id='UcHUF'><q id='UcHUF'></q></dir></style></legend>

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

                  问题描述

                  这很难看.有什么更 Pythonic 的方式来做到这一点?

                  This is ugly. What's a more Pythonic way to do it?

                  import datetime
                  
                  t= (2010, 10, 2, 11, 4, 0, 2, 41, 0)
                  dt = datetime.datetime(t[0], t[1], t[2], t[3], t[4], t[5], t[6])
                  

                  推荐答案

                  一般可以使用func(*tuple)语法.您甚至可以传递元组的一部分,这看起来就像您在这里尝试做的那样:

                  Generally, you can use the func(*tuple) syntax. You can even pass a part of the tuple, which seems like what you're trying to do here:

                  t = (2010, 10, 2, 11, 4, 0, 2, 41, 0)
                  dt = datetime.datetime(*t[0:7])
                  

                  这被称为 unpacking 元组,也可以用于其他可迭代对象(例如列表).这是另一个示例(来自 Python 教程):

                  This is called unpacking a tuple, and can be used for other iterables (such as lists) too. Here's another example (from the Python tutorial):

                  >>> range(3, 6)             # normal call with separate arguments
                  [3, 4, 5]
                  >>> args = [3, 6]
                  >>> range(*args)            # call with arguments unpacked from a list
                  [3, 4, 5]
                  

                  这篇关于解压元组的pythonic方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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='sjZui'></bdo><ul id='sjZui'></ul>
                    <i id='sjZui'><tr id='sjZui'><dt id='sjZui'><q id='sjZui'><span id='sjZui'><b id='sjZui'><form id='sjZui'><ins id='sjZui'></ins><ul id='sjZui'></ul><sub id='sjZui'></sub></form><legend id='sjZui'></legend><bdo id='sjZui'><pre id='sjZui'><center id='sjZui'></center></pre></bdo></b><th id='sjZui'></th></span></q></dt></tr></i><div id='sjZui'><tfoot id='sjZui'></tfoot><dl id='sjZui'><fieldset id='sjZui'></fieldset></dl></div>

                      <tfoot id='sjZui'></tfoot>
                        • <small id='sjZui'></small><noframes id='sjZui'>

                            <legend id='sjZui'><style id='sjZui'><dir id='sjZui'><q id='sjZui'></q></dir></style></legend>
                              <tbody id='sjZui'></tbody>