<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國際加速解決方案。 廣告
                # `__name__ == "__main__"`是什么? > 原文: [https://thepythonguru.com/what-is-if-__name__-__main__/](https://thepythonguru.com/what-is-if-__name__-__main__/) * * * 于 2020 年 1 月 7 日更新 * * * Python 中的每個模塊都有一個稱為`__name__`的特殊屬性。 當模塊作為主程序運行時,`__name__`屬性的值設置為`'__main__'`。 否則,將`__name__`的值設置為包含模塊的名稱。 考慮以下代碼,以更好地理解。 ```py # file my_module.py foo = 100 def hello(): ? ? print("i am from my_module.py") if __name__ == "__main__": ? ? print("Executing as main program") ? ? print("Value of __name__ is: ", __name__) ? ? hello() ``` 在這里,我們定義了一個新模塊`my_module`。 通過輸入以下代碼,我們可以將該模塊作為主程序執行: ```py python my_module.py ``` **預期輸出**: ```py Executing as main program Value of __name__ is: __main__ i am from my_module.py ``` ```py # file my_module.py foo = 100 def hello(): print("i am from my_module.py") if __name__ == "__main__": print("Executing as main program") print("Value of __name__ is: ", __name__) hello() ``` 在這里,我們正在創建一個新模塊并將其作為主程序執行,因此`__name__`的值設置為`'__main__'`。 結果,如果條件滿足,則函數`hello()`被調用。 現在創建一個名為`module.py`的新文件,并編寫以下代碼: ```py import my_module print(my_module.foo) my_module.hello() print(my_module.__name__) ``` **預期輸出**: ```py 100 i am from my_module.py my_module ``` 如您現在所見,由于`__name__`的值設置為`'my_module'`,因此`my_module`中的`if`語句執行失敗。 * * * * * *
                  <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>

                              哎呀哎呀视频在线观看