Conditional Expressions in Python 2.4

bruno at modulix onurb at xiludom.gro
Fri Jun 2 11:24:07 CEST 2006


A.M wrote:
> Hi,
> 
> 
> 
> I am using Python 2.4. I read the PEP 308 at:
> 
> http://www.python.org/dev/peps/pep-0308/
> 
> I tried the statement:
> 
> a= "Yes" if 1==1 else "No"
> 
> but the interpreter doesn't accept it.
> 
> Do we have the conditional expressions in Python 2.4?

No, AFAIK they'll be in for 2.5

In the meanwhile, there are (sometime trickyà ways to get the same result:

a = 1 == 1 and "Yes" or "No"
a = ("No", "Yes")[1 == 1]


-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"



More information about the Python-list mailing list