正常的情况下,finally作用域的代码一定会被执行的,不管是否发生异常。哪怕是调用了sys.exit函数,finally也是会被执行的。
那怎么样才能让finally代码不执行了。
importtime choice=True try: ifchoice: whileTrue: pass else: print"Pleasepulltheplugonyourcomputersometimesoon..." time.sleep(60*60*24*365) finally: print"Finally..."原文来自:https://www.py.cn
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
暂无评论内容