<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # Python `enumerate()`函數 > 原文: [https://thepythonguru.com/python-builtin-functions/enumerate/](https://thepythonguru.com/python-builtin-functions/enumerate/) * * * 于 2020 年 1 月 7 日更新 * * * `enumerate()`函數采用一個可迭代對象,并返回一個枚舉對象(一個迭代器),該對象生成一個格式為`(index, item)`的元組,其中`index`指該項目的偏移量,`item`指的是可迭代對象中的對應的項目。 `enumerate()`函數的語法如下: **語法**: ```py enumerate(iterable[, start=0]) -> iterator for index, value of iterable ``` | 參數 | 描述 | | --- | --- | | `iterable` | (必需)任何可迭代的對象,例如字符串,列表,字典等。 | | `start`(可選) | `index`的初始值。 默認為`0`。 | 這是一個例子: ```py >>> >>> list(enumerate("hello")) [(0, 'h'), (1, 'e'), (2, 'l'), (3, 'l'), (4, 'o')] >>> >>> >>> for index, value in enumerate("hello"): ... print(index, value) ... 0 h 1 e 2 l 3 l 4 o >>> ``` 試試看: ```py print( list(enumerate("hello")) ) for index, value in enumerate("hello"): print(index, value) ``` 以下清單顯示`enumerate()`如何與清單,字典和元組一起使用: ```py >>> >>> for index, value in enumerate([110, 45, 12, 891, "one"]): ... print(index, value) ... 0 110 1 45 2 12 3 891 4 one >>> >>> >>> for index, value in enumerate({'name': 'Jane', 'age': 26, 'salary': 40000}): ... print(index, value) ... 0 name 1 salary 2 age >>> >>> >>> for index, value in enumerate({1, 290, -88, 10}): ... print(index, value) ... 0 -88 1 1 2 10 3 290 >>> ``` 試一試: ```py for index, value in enumerate([110, 45, 12, 891, "one"]): print(index, value) print("-"*20) for index, value in enumerate({'name': 'Jane', 'age': 26, 'salary': 40000}): print(index, value) print("-"*20) for index, value in enumerate({1, 290, -88, 10}): print(index, value) ``` ## 設置索引的初始值 * * * 要設置索引的初始值,我們使用`start`關鍵字參數。 ```py >>> >>> list(enumerate("hello", start=2)) [(2, 'h'), (3, 'e'), (4, 'l'), (5, 'l'), (6, 'o')] >>> >>> >>> for index, value in enumerate("hello", start=2): ... print(index, value) ... 2 h 3 e 4 l 5 l 6 o >>> ``` 試一試: ```py print( list(enumerate("hello", start=2)) ) for index, value in enumerate("hello", start=2): print(index, value) ``` * * * * * *
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看