if does not evaluate
bbelguise at FT
bbelguise at FT
Wed Jun 16 12:10:32 EDT 2004
And with list comprehension
if [x for x in Liste if x=="Red"]
"Nicolas Fleury" <nid_oizo at yahoo.com_remove_the_> a écrit dans le message
news: fXqxc.31545$sS2.941770 at news20.bellglobal.com...
> Robert Brewer wrote:
> > If your main desire is to code in some other language while still using
> > Python, write your own VB-style IIf function:
>
> All the solutions you propose don't work (except the long form). You
> cannot code an "iif" function. Test:
>
> def iif(cond, expr1, expr2):
> if cond: return expr1
> return expr2
> def foo(x): return iif(x == 0, 0, 1.0/x)
> foo(4)
> foo(0)
>
> See PEP 308.
>
> Regards,
> Nicolas
More information about the Python-list
mailing list