Py3K idea: why not drop the colon?

Ron Adam rrr at ronadam.com
Sat Nov 11 19:54:35 CET 2006


Steven D'Aprano wrote:
> On Sat, 11 Nov 2006 01:13:03 -0600, Ron Adam wrote:
> 
>> Steven D'Aprano wrote:
>>> On Fri, 10 Nov 2006 21:24:50 +0100, Bjoern Schliessmann wrote:
>>>
>>>> Marc 'BlackJack' Rintsch wrote:
>>>>
>>>>> No it doesn't -- look again at the example given above.  It's
>>>>> legal syntax in Python but doesn't have the semantics implied by
>>>>> the example.
>>>> Sorry, I don't understand -- what is the difference between the
>>>> example as it is and the implied semantics of it?
>>> Inform 6 "x == blue or red or yellow" is equivalent to the Python
>>>  
>>> x == blue or x == red or x == yellow
>> Maybe it should have been expressed as:
>>
>>      x == (blue or red or yellow)
> 
> 
> But that has very different semantics still -- since parentheses have the
> highest priority, it means "evaluate (blue or red or yellow), then test if
> x is equal to the result".
> 
> It might be useful on occasion to have a construct for "x equals blue or
> red or yellow" in the sense used by normal English or Inform 6. And,
> funnily enough, Python has such a construct. You just have to write "in"
> instead of ==, and use a tuple for the terms:
> 
> x in (blue, red, yellow)
> 
> Not hard to remember, and unambiguous.

Yes, that is the correct best way to do it, of course.

Funny thing is I tested a variation of the above version in a console and it 
seemed to work, which surprised me.  Now I can't get it to work, <scratching 
head>.  I don't know exactly what I typed in last night, so I can't figure out 
what subtle (or overlooked obvious) characteristics my test had which gave me 
the misleading results.

Sigh. I did think it was kind of odd it (apparently) worked, which was why I 
phrased it as a suggestion.

Cheers,
    Ron




More information about the Python-list mailing list