[Python-ideas] a in x or in y

Steven D'Aprano steve at pearwood.info
Fri Feb 14 11:20:54 CET 2014


On Thu, Feb 13, 2014 at 10:27:19PM +1100, Chris Angelico wrote:

> Generalizing the syntax, I'd see this as:
> 
> operand1 binary-op1 operand2 {and|or} binary-op2 operand3
[...]
> The way I see it, there should ideally be no syntactic rule against
> using different operators on the two sides:
> 
> input("> ") in legalcommands and not in forbiddencommands
> value > 20 or in {3,5,7,11}

I would rather be conservative about adding new syntax in this way. It's 
easier to generalise later than to make it less general. I don't mind 
chaining "in" or "not in", I mind a bit that one might extend that to 
other comparisons, and I *really strongly dislike* that one might write 
something like this without the compiler complaining:

x + 23 or * 2

Although we might declare that this is to understood as "x+23 or x*2", I 
think it's ugly and weird and doesn't read like executable pseudo-code. 
To me, it feels almost Forth-like (and I like Forth, as Forth, just not 
in Python code). 


-- 
Steven


More information about the Python-ideas mailing list