On Tuesday, September 26, 2017 at 2:54:32 PM UTC-7, Chris Angelico wrote: > On Wed, Sep 27, 2017 at 7:43 AM, Cai Gengyang <gengyang...@gmail.com> wrote: > > Help check if my logic is correct in all 5 expressions > > > > > > A) Set bool_one equal to the result of > > False and False > > > > Entire Expression : False and False gives True because both are False > > This is not correct, and comes from a confusion in the English > language. In boolean logic, "and" means "both". For instance: > > *IF* we have eggs, *AND* we have bacon, *THEN* bake a pie. > > Can you bake an egg-and-bacon pie? You need *both* ingredients. The > assertion "we have eggs" is True if we do and False if we do not; and > the overall condition cannot be True unless *both* assertions are > True. > > In Python, the second half won't even be looked at if the first half > is false. That is to say, Python looks beside the stove to see if > there's a carton of eggs, and if it can't see one, it won't bother > looking in the freezer for bacon - it already knows we can't bake that > pie. > > Your other questions are derived from this one, so you should be fine > once you grok this one concept. > > ChrisA
A way to prove this: def funcA(): print('In function A') return False def funcB(): print('In function B') return False print(funcA() and funcB()) This will print 'In function A' followed by 'False'. It will not print 'In function B' at all. -- https://mail.python.org/mailman/listinfo/python-list