Mega Code Archive

 
Categories / Python Tutorial / Statement
 

The finally clause will execute, whether there was an error encountered or not

try:    v = int( raw_input("Enter a value: "))    print "We got some valid input!"    x = 100 / v except (KeyboardInterrupt):    print "well, ok, if you don't really want to.." except ZeroDivisionError:    print "You can't divide by ZERO!" except:     print "Some other error happened here" else:     print "All went well, x = ", x finally:     print "This is executed no matter what!"