@Selena, The method varies with the type of variable.
1. If you want to check the existence of a local variable use:
if 'yourVar' in locals():
# yourVar exists.
2.if you want to check the existence of a global variable use:
if 'yourVar' in globals():
# yourVar exists.
3.If you want to check if an object has an attribute:
if hasattr(obj, 'name_attr'):
# obj.name_attr exists.
Hope this helps!