• <bdo id='vvlFE'></bdo><ul id='vvlFE'></ul>
  1. <tfoot id='vvlFE'></tfoot>
  2. <small id='vvlFE'></small><noframes id='vvlFE'>

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

      在 Python 中,我如何声明一个动态数组

      时间:2023-07-05
        <bdo id='obJ9k'></bdo><ul id='obJ9k'></ul>
            <legend id='obJ9k'><style id='obJ9k'><dir id='obJ9k'><q id='obJ9k'></q></dir></style></legend><tfoot id='obJ9k'></tfoot>

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

                <i id='obJ9k'><tr id='obJ9k'><dt id='obJ9k'><q id='obJ9k'><span id='obJ9k'><b id='obJ9k'><form id='obJ9k'><ins id='obJ9k'></ins><ul id='obJ9k'></ul><sub id='obJ9k'></sub></form><legend id='obJ9k'></legend><bdo id='obJ9k'><pre id='obJ9k'><center id='obJ9k'></center></pre></bdo></b><th id='obJ9k'></th></span></q></dt></tr></i><div id='obJ9k'><tfoot id='obJ9k'></tfoot><dl id='obJ9k'><fieldset id='obJ9k'></fieldset></dl></div>
                  <tbody id='obJ9k'></tbody>
              • 本文介绍了在 Python 中,我如何声明一个动态数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我想声明一个数组,并且应该删除 ListBox 中存在的所有项目,而不管 ListBox 中存在的组名称如何.任何人都可以帮助我用 Python 编码.我正在使用 WINXP 操作系统 &Python 2.6.

                I want to declare an Array and all items present in the ListBox Should Be deleted irrespective of the Group name present in the ListBox. can any body help me coding in Python. I am using WINXP OS & Python 2.6.

                推荐答案

                在 Python 中,list 是一个动态数组.您可以像这样创建一个:

                In Python, a list is a dynamic array. You can create one like this:

                lst = [] # Declares an empty list named lst
                

                或者你可以用物品填充它:

                Or you can fill it with items:

                lst = [1,2,3]
                

                您可以使用追加"添加项目:

                You can add items using "append":

                lst.append('a')
                

                您可以使用 for 循环遍历列表的元素:

                You can iterate over elements of the list using the for loop:

                for item in lst:
                    # Do something with item
                

                或者,如果您想跟踪当前索引:

                Or, if you'd like to keep track of the current index:

                for idx, item in enumerate(lst):
                    # idx is the current idx, while item is lst[idx]
                

                要删除元素,可以使用 del 命令或 remove 函数,如下所示:

                To remove elements, you can use the del command or the remove function as in:

                del lst[0] # Deletes the first item
                lst.remove(x) # Removes the first occurence of x in the list
                

                但请注意,不能同时遍历列表并对其进行修改;为此,您应该迭代列表的一部分(基本上是列表的副本).如:

                Note, though, that one cannot iterate over the list and modify it at the same time; to do that, you should instead iterate over a slice of the list (which is basically a copy of the list). As in:

                 for item in lst[:]: # Notice the [:] which makes a slice
                       # Now we can modify lst, since we are iterating over a copy of it
                

                这篇关于在 Python 中,我如何声明一个动态数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:如何从两个Listbox中同时选择? 下一篇:获取列表框中的选定项目并调用另一个存储选定项目的函数

                相关文章

              • <small id='CXgzh'></small><noframes id='CXgzh'>

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

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

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