> On Dec 21, 2019, at 08:41, Soni L. <[email protected]> wrote:
>
> I'd like to see the ability to do:
>
> if x:
> 1
> and if y:
> 2
> or if z:
> 3
>
> The truth table for these would be:
>
> x | y | z | result
> 0 | _ | 0 | (none)
> 0 | _ | 1 | 3
> 1 | 0 | _ | 1,3
> 1 | 1 | _ | 1,2,3
>
> and each statement is evaluated once, when encountered. (as such, y and z may
> not be evaluated at all, if their evaluation is not necessary to determine
> the outcome.)
So this is equivalent to:
if x:
if y:
1, 2, 3
else:
1, 3
elif z:
3
I can see how the former saves me having to repeat the 3 three times. But the
cost is being less obvious about when exactly I get a 3 so I’m forced to work
it through step by step—including the confusion about the 1,0,0 case, which, as
you mentioned, is only clear if you imagine putting an else at the end
(although maybe you’d get used to that once you’d read through enough of
these?). It’s even less obvious if you do throw in an elif, or just add an and
if to the end (so now the condition to get there is not “x and y or z and w”
but, I think, “((x and y) or z) and w”?
Does that advantage outweigh the disadvantage? Certainly not for this example.
But that’s probably because even the rewritten example is meaningless and
useless. Maybe it would be different with a realistic use case, but I can’t
imagine what that would be. Surely you must have some case where you really
wanted this, that motivated you to propose it?
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/BSWD7WSSJRL6J3RAO4OH7LMIJZ7LIAHE/
Code of Conduct: http://python.org/psf/codeofconduct/