I have this function:
def foo():
a = []
if not a:
print "empty"
return None
else:
print "not empty"
return a
Is there any Exception that do the same? Just to remove the if condition. Something like this:
def foo(list):
try:
a = list
return a
except:
return None
if not a:
will always beTrue
...also, please don't uselist
as a variable name. – TassNone
instead of an empty list? An empty list already evaluates to a booleanFalse
, so what's the reasoning behind your question? – Tass