Default if none

Astley Le Jasper astley.lejasper at
Thu Apr 29 06:16:24 EDT 2010

I realise I could roll my own here, but I wondered if there was an
inbuilt version of this?

def default_if_none(*args):
    for arg in args:
        if arg:
            return arg
    return None

x = None
y = 5
z = 6

print default_if_none(x,y,z)

>> 5

More information about the Python-list mailing list