“Cómo verificar si VAR existe Python” Código de respuesta

Cómo verificar si existe una variable en Python

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

#if the variable is global:
if 'myVar' in globals():
  # myVar exists.
Worried Wryneck

Cómo verificar si VAR existe Python

# for local
if 'myVar' in locals():
  # myVar exists.
# for globals
if 'myVar' in globals():
  # myVar exists.
Filthy Fish

Respuestas similares a “Cómo verificar si VAR existe Python”

Preguntas similares a “Cómo verificar si VAR existe Python”

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código