1. <legend id='ookML'><style id='ookML'><dir id='ookML'><q id='ookML'></q></dir></style></legend>
          <bdo id='ookML'></bdo><ul id='ookML'></ul>

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

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

      2. <tfoot id='ookML'></tfoot>

        Python - 初始化多个列表/行

        Python - Initializing Multiple Lists/Line(Python - 初始化多个列表/行)
        <tfoot id='Zs3rM'></tfoot>
          <tbody id='Zs3rM'></tbody>
        <i id='Zs3rM'><tr id='Zs3rM'><dt id='Zs3rM'><q id='Zs3rM'><span id='Zs3rM'><b id='Zs3rM'><form id='Zs3rM'><ins id='Zs3rM'></ins><ul id='Zs3rM'></ul><sub id='Zs3rM'></sub></form><legend id='Zs3rM'></legend><bdo id='Zs3rM'><pre id='Zs3rM'><center id='Zs3rM'></center></pre></bdo></b><th id='Zs3rM'></th></span></q></dt></tr></i><div id='Zs3rM'><tfoot id='Zs3rM'></tfoot><dl id='Zs3rM'><fieldset id='Zs3rM'></fieldset></dl></div>

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

              • <legend id='Zs3rM'><style id='Zs3rM'><dir id='Zs3rM'><q id='Zs3rM'></q></dir></style></legend>
                  <bdo id='Zs3rM'></bdo><ul id='Zs3rM'></ul>
                  本文介绍了Python - 初始化多个列表/行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  这太丑了:

                  psData = []
                  nsData = []
                  msData = []
                  ckData = []
                  mAData = []
                  RData = []
                  pData = []
                  

                  有没有办法在一行中声明这些变量?

                  Is there a way to declare these variables on a single line?

                  推荐答案

                  alist, blist, clist, dlist, elist = ([] for i in range(5))
                  

                  上述方法的缺点是,您需要计算 = 左侧的名称数量并且具有完全相同数量的空列表(例如通过 range 调用,或更明确地)在右手边边.

                  The downside of above approach is, you need to count the number of names on the left of = and have exactly the same number of empty lists (e.g. via the range call, or more explicitly) on the right hand side.

                  最主要的是,不要使用类似

                  alist, blist, clist, dlist, elist = [[]] * 5
                  

                  也没有

                  alist = blist = clist = dlist = elist = []
                  

                  这将使所有名称都引用相同空列表!

                  which would make all names refer to the same empty list!

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

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

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

                        <tfoot id='CRC7r'></tfoot>
                          <bdo id='CRC7r'></bdo><ul id='CRC7r'></ul>