?: in Python

Steven D'Aprano steve at REMOVETHIScyber.com.au
Wed Dec 14 16:50:34 EST 2005


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.



-- 
Steven.




More information about the Python-list mailing list