Tell me the truth

francois.petitjean at francois.petitjean at
Thu Mar 8 20:41:55 CET 2007

Duncan Booth wrote :
> francois.petitjean at 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?
>>> Python = cool = True
>>> Python is cool
>>> Python is cool is True
# heh  it seems possible to tackle is True to a boolean expression (not
>>> it = False
>>> Python is cool is not it
# I knew that. slef evident...
>>> Python = cool = False
>>> Python is cool is not it
# 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
# Yeah!


   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
   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
   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