> I'm coding in python and I need to print something if a variable isnt set to anything. How could I check that? Can I

I'm coding in python and I need to print something if a variable isnt set to anything. How could I check that? Can I

Posted at: 2014-12-18 
The standard way is to use try/except. something like:

try:

.... var_name

.... print ( "var_name is defined." )

except NameError:

.... print ( "var_name is not defined" )

This has limited use, I think, and you'd do something besides those print calls, but this is in Python's spirit of "It's easier to ask for forgiveness than for permission." (EAFP for short)

while im not familiar with python yes an if statement is one way you could check. you could go through the python documentation and see if theres maybe a libary that already accomplishes that.

myVar = 0

# here, stuff happens

if myVar == 0:

????print "something"