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

Bo Peng bpeng at rice.edu
Sat Jun 18 22:15:48 EDT 2005


>>In Python, I am using temporary variables like
>>
>>if cond1:
>>   para1 = a
>>else:
>>   para1 = b
>>
>># ....
>># a bunch of such if/else
>>
>>func(para1, para2,...)
> 
> 
> Yeah, that's how I would do it.  How many of these things do you have?

I have around 10 of them. Using these if/else, it will take 50 lines for 
a function call. It also bothers me to have 10 variables left in the 
namespace, in addition to finding 10 meaningful names.

The FAQ provides two solutions, neither of them are elegant. I guess I 
will use if/else for reasability purpose.

Thanks.
Bo



More information about the Python-list mailing list