$10K coding deathmatch
Levi Pearson
levi at cold.org
Sat Nov 4 12:37:02 MST 2006
On Nov 4, 2006, at 11:14 AM, Jonathan Ellis wrote:
>> This means you pretty much have to
>> use and/or for inline conditionals, as far as I know.
>
> you can do this with boolean operators in early python versions
>
> a = condition and trueval or falseval
>
Right, that's what I meant by 'use and/or for inline conditionals' in
the above statement, and it's what the code I was responding to did.
> this doesn't quite work if trueval happens to evaluate to false, so in
> python 2.5 you can write
>
> a = trueval if condition else falseval
Cool, I didn't know about that. Haven't been paying too much
attention to Python lately, and the python I've got on this box isn't
up to date. It's definitely nicer to have a conditional expression
than to have to rely on the short-circuit behavior of boolean
expressions.
--Levi
More information about the PLUG
mailing list