Tell me the truth

francois.petitjean at bureauveritas.com francois.petitjean at bureauveritas.com
Thu Mar 8 14:41:55 EST 2007


Duncan Booth wrote :
> francois.petitjean at bureauveritas.com wrote:

>> After much head scrating and experimenting with dis.dis() I have found
>> that chaining comparisons (with is or ==)  a == b == c in Python is
>> never a good idea. It is interpreted as
>>  ( a == b ) and ( b == c)
>> Such a magic is fine  when we write:
>>  if  0.0 <= x < 1.0:
>> but it renders the outcome of  if a == b == c: somewhat confusing.

> I don't understand why it is confusing. What other meaning would you
> expect?
Consider:
>>> Python = cool = True
>>> Python is cool
True
>>> Python is cool is True
True
# heh  it seems possible to tackle is True to a boolean expression (not
always)
>>> it = False
>>> Python is cool is not it
True
# I knew that. slef evident...
>>> Python = cool = False
>>> Python is cool is not it
False
# Waht? desillution...
# Ough! You must reread the reference documentation on chaining the
comparison operators and understand the semantics (the two comparisons are
'anded' and 'and' shortcircuits in Python).
>>> Python is cool
True
# Yeah!

Regards


   NOTICE: This message contains information which is confidential and the
   copyright of our company or a third  party. If you are not the intended
   recipient of this message please delete it and destroy all copies. If
   you
   are the intended recipient of this message you should not disclose or
   distribute this message to third parties without the consent of our
   company. Our company does not represent, warrant and/or guarantee that
   the integrity of this message has been maintained nor that the
   communication is free of virus, interception or interference. The
   liability of our company is limited by our General Conditions of
   Services.
   Nota : Ce message contient des informations confidentielles propriété de
   notre société et/ou d'un tiers. Si vous n'êtes pas parmi les
   destinataires désignés de ce message, merci de l'effacer ainsi que
   toutes ses copies. Si vous êtes parmi les destinataires désignés de ce
   message, prière de ne pas le divulguer ni de le transmettre à des tiers
   sans l'accord de notre société. Notre société ne peut garantir que
   l'intégrité de ce message a été préservée ni que la présente
   communication est sans virus, interception ou interférence. La
   responsabilité de notre société est limitée par nos Conditions Générales
   de Services.





More information about the Python-list mailing list