This is pretty basic but I was coding and started wondering if there was a pythonic way to check if something does not exist. Here's how I do it if its true:
var = 1
if var:
print 'it exists'
but when I check if something does not exist, I often do something like this:
var = 2
if var:
print 'it exists'
else:
print 'nope it does not'
Seems like a waste if all I care about is knIs there a way to check if something does not exist without the else?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…