# 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
Here is what the above code is Doing:
1. We create a variable named variable and set it equal to 42.
2. We print the value of variable.
3. We delete the variable named variable.
4. We try to print the value of variable again.
The output of the code is:
NameError: name ‘variable’ is not defined
The first print statement works because the variable exists. The second print statement doesn’t work because the variable no longer exists.