如何简单地理解Python中的if __name__ == '__main__'
HuangCongQing opened this issue · comments
if __name__ == '__main__'的意思是:当.py文件被直接运行时,if __name__ == '__main__'之下的代码块
将被运行;当.py文件以模块形式被导入时,if __name__ == '__main__'之下的代码块不被运行。
Reference:
Python学习
Repository from Github https://github.comHuangCongQing/Python
HuangCongQing opened this issue · comments
if __name__ == '__main__'的意思是:当.py文件被直接运行时,if __name__ == '__main__'之下的代码块
将被运行;当.py文件以模块形式被导入时,if __name__ == '__main__'之下的代码块不被运行。
Reference: