Is there something similar to ?: operator (C/C++) in Python?

Ron Adam rrr at
Mon Jun 20 08:36:42 CEST 2005

Ron Adam wrote:

> You might be able to use a dictionary of tuples.
> call_obj = {(type_obj1,0):obj1a,
>             (type_obj1,0):obj1b,
>             (type_boj2,1):obj2a,
>             (type_obj2,1):obj2b,
>             etc... }
> call_obj[(type_of_obj,order)]()
> Regards, Ron

This won't work like I was thinking it would.

But to get back to your is there a ? operator question...

Try this.

def foo():
    return "foo"

def boo():
    return "boo"

print (foo, boo)[1>0]()    # prints "boo"
print (foo, boo)[1<0]()    # prints "foo"


More information about the Python-list mailing list