On Thu, Apr 29, 2010 at 3:16 AM, Astley Le Jasper
<astley.lejas...@gmail.com> wrote:
> 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)

If none of the potential values are considered boolean false:

print x or y or z

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to