<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智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                [TOC] 遍歷 通過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. 字典遍歷 <1> 遍歷字典的key(鍵) <2> 遍歷字典的value(值) <3> 遍歷字典的項(元素) <4> 遍歷字典的key-value(鍵值對) 遍歷 通過for ... in ...:的語法結構,我們可以遍歷字符串、列表、元組、字典等數據結構。 注意python語法的縮進 字符串遍歷 >>> a_str = "hello itcast" >>> for char in a_str: ... print(char,end=' ') ... h e l l o i t c a s t 列表遍歷 >>> a_list = [1, 2, 3, 4, 5] >>> for num in a_list: ... print(num,end=' ') ... 1 2 3 4 5 元組遍歷 >>> a_turple = (1, 2, 3, 4, 5) >>> for num in a_turple: ... print(num,end=" ") 1 2 3 4 5 字典遍歷 <1> 遍歷字典的key(鍵) <2> 遍歷字典的value(值) <3> 遍歷字典的項(元素) <4> 遍歷字典的key-value(鍵值對) 想一想,如何實現帶下標索引的遍歷 ~~~ >>> 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 ~~~ ## 5. enumerate() 帶下標 ~~~ >>> chars = ['a', 'b', 'c', 'd'] >>> for i, chr in enumerate(chars): ... print i, chr ... 0 a 1 b 2 c 3 d >>> 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 >>> 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>

                              哎呀哎呀视频在线观看