Answers for "check if varibale exists python"

5

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
-1

check if variable exists python

try:
    myVar
except NameError:
    myVar = None      # or some other default value.

# Now you're free to use myVar without Python complaining.
Posted by: Guest on April-22-2022

Code answers related to "check if varibale exists python"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language