Skip to content

TypeScript code snippet – How to check if a variable exists in python?

#if the variable is local: 
if 'myVar' in locals():
  # myVar exists

#if the variable is global:
if 'myVar' in globals():
  # myVar exists.
See also  How to make tic tac toe in Python?

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.