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

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # 嵌套循環 > 原文: [https://pythonbasics.org/nested-loops/](https://pythonbasics.org/nested-loops/) 一個循環可以包含一個或多個其他循環:您可以在一個循環內創建一個循環。此原理稱為嵌套循環。 嵌套循環遍歷兩個或多個循環。 程序員通常嵌套 2 或 3 層深度。 高于此的數字只會造成混亂。 ## 示例 讓我們做一個簡單的例子。 我們創建兩個列表: ```py persons = [ "John", "Marissa", "Pete", "Dayton" ] restaurants = [ "Japanese", "American", "Mexican", "French" ] ``` 如果我們有一個喜歡在餐廳吃飯的人的列表,我們可以讓他們每個人都在某個餐廳吃飯嗎? ```py #!/usr/bin/python persons = [ "John", "Marissa", "Pete", "Dayton" ] restaurants = [ "Japanese", "American", "Mexican", "French" ] for person in persons: for restaurant in restaurants: print(person + " eats " + restaurant) ``` 這遍歷了兩個循環: ![nested loop output](https://img.kancloud.cn/12/03/12039ae85723ca10ccfcd9660afad640_580x314.jpg) ## 練習 試試下面的練習 1. 給定一個 3x3 的井字游戲板,請打印每個位置 2. 創建一個程序,讓每個人都與其他人見面 `persons = [ “John”, “Marissa”, “Pete”, “Dayton” ]` 3. 如果正常的`for`循環在 n 步`O(n)`中完成,則嵌套循環有多少步? 完成這些步驟后,繼續下一個練習。 [下載示例](https://gum.co/dcsp)
                  <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>

                              哎呀哎呀视频在线观看