if __name__ == "__main__":
时间: 2023-10-28 19:06:06 浏览: 87
Python中_name==_main的解释
if __name__ == "__main__"是一个Python中常见的代码块。这个代码块的意思是,当.py文件被直接运行时,即作为脚本运行时,if __name__ == "__main__"之后的代码块将会被执行。但是,当.py文件作为模块被导入时,if __name__ == "__main__"之后的代码块将不会被执行。这个代码块通常被用来测试函数的功能或者作为脚本的入口点。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [如何简单地理解Python中的if __name__ == '__main__'](https://blog.csdn.net/yjk13703623757/article/details/77918633)[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: 50%"]
- *2* [if __name__ == ‘__main__’的用法](https://blog.csdn.net/CSDN_lzw99/article/details/124249393)[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: 50%"]
[ .reference_list ]
阅读全文