Conditional expressions (again)
gbreed at cix.compulink.co.uk
gbreed at cix.compulink.co.uk
Fri Oct 26 07:23:50 EDT 2001
Erik Max Francis wrote:
> Greg Ewing wrote:
>
> > Write that as
> >
> > x = (
> > b if a else
> > d if c else
> > e
> > )
> >
> > and it looks a lot clearer.
>
> Sure, but since conditional expressions are intended for brevity, you've
> just made a five line nested conditional express. Why not just use an
> if ... elif ... else statement instead?
Compare
order.append(
spam if customer == michae1 else
eggs if customer == john else
cheese)
with
if customer == michael:
side0rder = spam
elif customer == john:
sideOrder = eggs
else:
sideOrder = cheese
order.append(sideOrder)
in terms of how likely each error is to arise in testing, and how much
time it would take to work out what was going wrong. I find that almost
convincing ;-)
Graham
More information about the Python-list
mailing list