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

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # 遍歷 通過for ... in ... 我們可以遍歷字符串、列表、元組、字典等 **注意python語法的縮進** ## 1\. 字符串遍歷 ~~~ >>> a_str = "hello itcast" >>> for char in a_str: ... print(char,end=' ') ... h e l l o i t c a s t ~~~ ## 2\. 列表遍歷 ~~~ >>> a_list = [1, 2, 3, 4, 5] >>> for num in a_list: ... print(num,end=' ') ... 1 2 3 4 5 ~~~ ## 3\. 元組遍歷 ~~~ >>> a_turple = (1, 2, 3, 4, 5) >>> for num in a_turple: ... print(num,end=" ") 1 2 3 4 5 ~~~ ## 4\. 字典遍歷 #### 4.1. 遍歷字典的key(鍵) ![](https://img.kancloud.cn/5f/a8/5fa8d251a3e18b0271dcc613d56116a5_347x112.png) #### 4.2. 遍歷字典的value(值) ![](https://img.kancloud.cn/5b/7e/5b7e39060a1f5cce975d99e09e3475d3_348x121.png) #### 4.3. 遍歷字典的項(元素) ![](https://img.kancloud.cn/7d/9c/7d9c47f66329897292d87318381d6126_352x119.png) #### 4.4. 遍歷字典的key-value(鍵值對) ![](https://img.kancloud.cn/f0/2c/f02caedb17941da8af330416c8c57205_390x123.png) ## 5\. 想一想,如何實現帶下標索引的遍歷 ~~~ >>> chars = ['a', 'b', 'c', 'd'] >>> i = 0 >>> for chr in chars: ... print("%d %s"%(i, chr)) ... i += 1 ... 0 a 1 b 2 c 3 d ~~~ ## 6\. enumerate() > enumerate() 函數用于將一個可遍歷的數據對象(如列表、元組或字符串)組合為一個索引序列,同時列出數據和數據下標,一般用在 for 循環當中。 ~~~ >>> chars = ['a', 'b', 'c', 'd'] >>> for i, chr in enumerate(chars): ... print i, chr ... 0 a 1 b 2 c 3 d ~~~
                  <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>

                              哎呀哎呀视频在线观看