# python if statements short circuit BUT be careful using not
a = list()
if not a:
print 'empty list'
a = None
if not a:
print 'None'
a = ''
if not a:
print 'empty string'
# explicit checking can avoid nasty bugs later
if result is not None and len( result ) == 0:
- - - - - - - - - - - - - - - - - - - -
# ternary operator, very useful for optional parameters def foo( num=None, mylist=None ):
num = num if num else 0 # assign num to 0 by default (if it's None or empty or ...)
mylist = mylist if mylist else [] # store the passed list or assign empty list
assert not isinstance( lst, basestring ) # input is a list or tuple (not a string)