?: in Python
Andy Leszczynski
yahoo at nospam.leszczynscy
Wed Dec 14 20:17:28 EST 2005
Steven D'Aprano wrote:
> On Wed, 14 Dec 2005 14:09:10 -0500, Andy Leszczynski wrote:
>
>
>>How can do elegantly in Python:
>>
>>if condition:
>> a=1
>>else:
>> a=2
>>
>>like in C:
>>
>>a=condition?1:2
>
>
> I thought you wanted to do it *elegantly*?
>
> Your first solution is perfectly elegant to my eyes, unlike that horrible
> C syntax.
I can tell you what is not elegant in the if else: approach. It is
logically a one operation while you are forced to use varaible "a"
twice. Fundamental flaw IMO.
A.
More information about the Python-list
mailing list