except indexerror as xx assigned the raised instance object the as is optional in try handler (if it' omittedthe instance is simply not assigned to name)but including it allows the handler to access both data in the instance and methods in the exception class this model works the same for user-defined exceptions we code with classes--the followingfor examplepasses to the exception class constructor arguments that become available in the handler through the assigned instanceclass myexc(exception)pass raise myexc('spam'exception class with constructor args tryexcept myexc as xinstance attributes available in handler print( argsbecause this encroaches on the next topicthoughi'll defer further details until then regardless of how you name themexceptions are always identified by class instance objectsand at most one is active at any given time once caught by an except clause anywhere in the programan exception dies ( won' propagate to another try)unless it' reraised by another raise statement or error scopes and try except variables we'll study exception objects in more detail in the next now that we've seen the as variable in actionthoughwe can finally clarify the related version-specific scope issue summarized in in python xthe exception reference variable name in an except clause is not localized to the clause itselfand is available after the associated block runsc:\codepy - try except exception as does not localize either way print integer division or modulo by zero zerodivisionerror('integer division or modulo by zero',this is true in whether we use the -style as or the earlier comma syntaxtry except exceptionx exception coding details