The correct way to delete a variable if it exists The correct way to delete a variable if it exists tkinter tkinter

The correct way to delete a variable if it exists


Use the del keyword

if 'l' in globals():    del l


You should use the global key word when declaring the variable l:

global l #declare the variable as globall = 'foo'