Posted on 25th July 2024|10 views
How do you check if a variable is not defined in Python?
Posted on 25th July 2024| views
You can check the variable is defined or not by using the below code
try:
a = 1
except NameError:
print("Variable isn’t defined")
else:
print("Variable is defined")
try:
b
except NameError:
print("Variable isn’t defined")
else:
print("Variable is defined")
Improve your knowledge in Python from scratch using Python Online Course.