finally里面只是执行完成try中的代码后,必须执行的代码,
即使是try中有异常抛出,也是会去执行finally。
>>> try: ... 1/0 ... finally: ... print "I just finally do something ,eg: clear!" ... I just finally do something ,eg: clear! Traceback (most recent call last): File "<stdin>", line 2, in <module> ZeroDivisionError: integer division or modulo by zero >>>
一般情况下,finally里面执行的都是一些清理工作,比如:关闭文件描述符,释放锁等