python写脚本测试执行为什么要写if __name__ == '__main__'

a56爆大奖在线娱乐的博客 在写python脚本的时候,例如,a56爆大奖在线娱乐写一个test1.py def test(n): print(n) if __name__ == '__main__': n = 1 test(1) 接下来打开cmd命令窗口,执行命令 python test.py 结果是把1打印出来 这时候就会有同学有
posted @ 2022-10-07 23:16  咻_python  阅读(208)  评论(0编辑  收藏  举报