Peter Otten writes: > Jussi Piitulainen wrote: > > > Thibault Langlois writes: > > > >> Hello, > >> > >> $ python > >> Python 2.7.4 (default, Sep 26 2013, 03:20:26) > >> [GCC 4.7.3] on linux2 > >> Type "help", "copyright", "credits" or "license" for more information. > >> >>> 1 > 0 == True > >> False > >> >>> (1 > 0) == True > >> True > >> >>> 1 > (0 == True) > >> True > >> >>> > >> > >> What am I missing here ? > > > > One or both of the following: > > > > >>> 0 == True > > False > > >>> True and False > > False > > >>> 1 > 0 > > True > > > > Or the fact that (1 > 0 == True) means ((1 > 0) and (0 == True)), > > where each expression in such a chain is evaluated once, though in > > this case it really does not matter since 0 is a literal. > > > > Hm, I don't know if the evaluation short-circuits. I think not, but > > I've never needed to know, and I don't need to know now. > > It is easy to check though: > > >>> def zero(): > ... print("zero") > ... return 0 > ... > >>> def one(): > ... print("one") > ... return 1 > ... > >>> def true(): > ... print("true") > ... return True > ... > >>> one() > zero() == true() > one > zero > true > False > >>> zero() > one() == true() > zero > one > False > > So yes, evaluation does short-curcuit.
Now I'm experiencing a mild form of information overload. Thanks anyway :) My guess was wrong. Now that I think of it, I've implemented a parser and evaluator once with this kind of chaining, and it may well have short-circuited. -- https://mail.python.org/mailman/listinfo/python-list