I am never going to complain about Python again

Frank Millman frank at chagford.com
Thu Oct 10 07:44:57 EDT 2013


"MRAB" <python at mrabarnett.plus.com> wrote in message 
news:52568B30.8040905 at mrabarnett.plus.com...
> On 10/10/2013 09:23, Frank Millman wrote:
>>
>> "Steven D'Aprano" <steve at pearwood.info> wrote in message
>> news:52562ee3$0$2931$c3e8da3$76491128 at news.astraweb.com...
>>> Just came across this little Javascript gem:
>>>
>>> ",,," == Array((null,'cool',false,NaN,4));
>>>
>>> => evaluates as true
>>>
>>> http://wtfjs.com/2011/02/11/all-your-commas-are-belong-to-Array
>>>
>>> I swear, I am never going to complain about Python again.
>>>
>>
>> I am sure you know this, but for the record, Javascript has two equality
>> operators, '==' and '==='.
>>
>> The double form attempts to coerce the left and right sides to the same
>> type, the triple form does not.
>>
> Re "==", this page:
>
>     http://php.net/manual/en/language.operators.comparison.php
>
> states:
>
> """If you compare a number with a string or the *comparison involves
> numerical strings*, then each string is converted to a number and the
> comparison performed numerically.""" (emphasis added)
>
> So they get coerced to numbers if they _look_ like numbers!
>

I just tested Steven's example.

",,," == Array((null,'cool',false,NaN,4)) evaluates to true

",,," === Array((null,'cool',false,NaN,4)) evaluates to false

I did look at the article that Steven linked to, but it made my eyes glaze, 
so don't ask me to explain it. I am prepared to use up a few brain cells 
trying to improve my own programming, but not trying to understand someone 
else's 'wtf' moments! [1]

Frank

[1]  Unless I have to maintain it, of course. I have been there before, and 
I have some dark memories!






More information about the Python-list mailing list