Inline Conditionals?
Jeffrey Froman
Jeffrey at Fro.man
Tue Aug 24 23:02:26 EDT 2004
Joshua Ginsberg wrote:
> def foo(x):
> return foo == 'bar' ? 'w00t' : 'l33t'
You could do something like:
def foo(x):
return ((x==bar) and 'w00t') or 'l33t'
But this doesn't work when you want to return a false value for a positive
result on your truth test. Thus:
def foo(x):
return ((x==None) and None) or x[:4]
always returns None, regardless of what x is.
Jeffrey
More information about the Python-list
mailing list