Answers for "python check if value is undefined"

1

python check if value is undefined

try:
    thevariable
except NameError:
    print("well, it WASN'T defined after all!")
else:
    print("sure, it was defined.")
Posted by: Guest on December-10-2020
4

how to check if var exists python

# for local
if 'myVar' in locals():
  # myVar exists.
# for globals
if 'myVar' in globals():
  # myVar exists.
Posted by: Guest on March-26-2020

Code answers related to "python check if value is undefined"

Python Answers by Framework

Browse Popular Code Answers by Language