Posted on 23rd April 2024
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.
STILL GOT QUERIES?