exit,return,sys.exit()等的区别与使用方法

http://blog.csdn.net/sruru/article/details/7815495

return:在定义函数时从函数中返回一个函数的返回值,终止函数的执行。

exit:下面的代码中,如果把sys.exit()替换成exit,则exit仅仅跳出离它最近的for循环, print "%s is legal identifier for Python!2" % idInput语句会被输出,这里,exit的作用类似于break. 但实际上break和exit作用并不同

os._exit( n)
Exit to the system with status n, without calling cleanup handlers, flushing stdio buffers, etc. Availability: Macintosh, Unix, Windows.

 

Note: The standard way to exit is sys.exit(n). _exit() should normally only be used in the child process after a fork().
sys.exit( [arg])

Exit from Python. This is implemented by raising the SystemExit exception, so cleanup actions specified by finally clauses of try statements are honored, and it is possible to intercept the exit attempt at an outer level.


请使用浏览器的分享功能分享到微信等