how to set a variable to undefined in python code example
Example 1: python undefine variable
# Basic syntax:
del variable
# Example usage:
variable = 42
print(variable)
--> 42
del variable
print(variable)
--> NameError: name 'variable' is not defined
# Note, this error is what we expect now that the variable has been
# deleted
Example 2: how to check if var exists python
# for local
if 'myVar' in locals():
# myVar exists.
# for globals
if 'myVar' in globals():
# myVar exists.