Understanding python try catch else finally clause behavior -
python 2.6.5 (r265:79063, oct 1 2012, 22:07:21)
i have this:
def f(): try: print "a" return except: print "b" else: print "c" finally: print "d" f() this gives:
a d and not expected
a c d if comment out return,
a c d how remember behavior in python?
when in doubt, consult the docs:
the optional
elseclause executed if , when control flows off end oftryclausecurrently, control “flows off end” except in case of exception or execution of
return,continue, orbreakstatement.
since you're returning body of try block, else not executed.
Comments
Post a Comment