# Variable 'last' may or may not be bound to a value at this point.
try:lastexcept NameError:last = None
# It will always now be bound to a value at this point.
if last is not None:draw(last, current);last = current
# Search for entry.for x in y:if x == 3:found = x
# Work with found entry.try:print('Found: {0}'.format(found))except NameError:print('Not found')else:# Handle rest of Found case here...
def no(var):"give var as a string (quote it like 'var')"assert(var not in vars())assert(var not in globals())assert(var not in vars(__builtins__))import keywordassert(var not in keyword.kwlist)
no('no')
---------------------------------------------------------------------------AssertionError Traceback (most recent call last)<ipython-input-88-d14ecc6b025a> in <module>----> 1 no('no')
<ipython-input-86-888a9df72be0> in no(var)2 "give var as a string (quote it)"3 assert( var not in vars())----> 4 assert( var not in globals())5 assert( var not in vars(__builtins__))6 import keyword
AssertionError:
import inspectdef exists_var(var_name):frame = inspect.currentframe()try:return var_name in frame.f_back.f_locals or var_name in globals()finally:del frame