python if __name__
时间: 2023-08-22 22:07:42 浏览: 190
Python中的if __name__语句用于判断当前模块是作为主程序运行还是作为模块被其他程序引用。当我们在一个Python模块中使用if __name__ == '__main__'时,这段代码块只有在该模块作为主程序运行时才会被执行,而当该模块被其他程序引用时,这段代码块不会被执行。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* *3* [一文弄懂Python中的 if __name__ == __main__](https://blog.csdn.net/sgzqc/article/details/124849467)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"]
[ .reference_list ]
阅读全文