Re: [Tutor] Boolean question
Hi Jack, On Wed, Mar 16, 2011 at 1:50 AM, Jack Trades jacktradespub...@gmail.com wrote: On Wed, Mar 16, 2011 at 12:22 AM, Donald Bedsole drbeds...@gmail.com wrote: not (False and True) Python evaluates it as True 1)You evaluate what's in the parentheses first. A thing can not be false and true at the same time, so the answer is false. Yes, the expression in the parenthesis is evaluated first. However it's not just one thing being evaluated. 'and' evaluates one argument at a time and returns immediately if the argument is False. In this case there are 2 distinct 'things'. False and True. False, obviously, evaluates to False, which causes 'and' to stop and return False. This reduces the expression to... not False 2)However, the not outside the parentheses flips the meaning of what is inside the parentheses, so false becomes True. ? Correct, the expression not False evaluates to True. Ok, so, as another example: not(True and False) is True because: the first argument True is true, and the second argument False when returned is negated by not becomes not False which evaluates to True? Thanks for the help! Btw, you're blog looks interesting; I'm going to have to check it our more closely later. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Boolean question
On Wed, Mar 16, 2011 at 1:24 AM, Donald Bedsole drbeds...@gmail.com wrote: Ok, so, as another example: not(True and False) is True because: the first argument True is true, and the second argument False when returned is negated by not becomes not False which evaluates to True? Correct. When Python sees (True and False) it first evaluates True, which is obviously True. Because the first argument was not False, it continues on and evaluates False. At this point Python stops evaluating anything else (for example if you had (True and False and True)) and returns False, which is then negated by 'not'. -- Jack Trades Pointless Programming Blog http://pointlessprogramming.wordpress.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Boolean question
Donald Bedsole drbeds...@gmail.com wrote most part. But, could someone make sure I'm understanding this one expression correctly? not (False and True) Python evaluates it as True Is it because: 1)You evaluate what's in the parentheses first. A thing can not be false and true at the same time, so the answer is false. 2)However, the not outside the parentheses flips the meaning of what is inside the parentheses, so false becomes True. ? Absolutely correct. Well done. Boolean algebra can be a weird thing to get your head around the first time you come across it :-) Here are some of the standard rules: True and thing = thing False and thing = False True or thing = True False or thing = thing And perhaps most bizarre of all: not(X or Y) = not X and not Y not(X and Y) = not X or not Y HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Boolean question
Hi Allen, Boolean algebra can be a weird thing to get your head around the first time you come across it :-) Yes, :-) Here are some of the standard rules: True and thing = thing False and thing = False True or thing = True False or thing = thing Thanks for your response and for the rules, but for some reason I'm not understanding. In the above quote, what is meant by thing? Thank you. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Boolean question
On 3/16/2011 4:26 PM, Donald Bedsole wrote: Hi Allen, Boolean algebra can be a weird thing to get your head around the first time you come across it :-) Yes, :-) Here are some of the standard rules: True and thing = thing False and thing = False True or thing = True False or thing = thing Thanks for your response and for the rules, but for some reason I'm not understanding. In the above quote, what is meant by thing? Thing in this context means 'anything. could be a string, number, list, any Python object. True and 1 = 1 True and 'a'= 'a' etc. -- Bob Gailer 919-636-4239 Chapel Hill NC ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Boolean question
On Wed, Mar 16, 2011 at 5:53 PM, bob gailer bgai...@gmail.com wrote: Thing in this context means 'anything. could be a string, number, list, any Python object. Ok, thanks Bob. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Boolean question
Hi Jack, On Wed, Mar 16, 2011 at 1:55 AM, Jack Trades jacktradespub...@gmail.com wrote: 'and' evaluates one argument at a time and returns immediately if the argument is False. And or works in the inverse manner? It evaluates one argument at a time and returns immediately if the argument is [True]. ? For example, not (True or False) False The first argument was True, so True was returned and negated by the not with a final result of False for the expression. Is this correct? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Boolean question
Donald Bedsole drbeds...@gmail.com wrote The first argument was True, so True was returned and negated by the not with a final result of False for the expression. Is this correct? Yes. Its called Short Circuit Evaluation. You will find an explanation on the Functional Programming topic of my tutor HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Boolean question
Donald Bedsole drbeds...@gmail.com wrote False or thing = thing Thanks for your response and for the rules, but for some reason I'm not understanding. In the above quote, what is meant by thing? Any Boolean value, and in Python that means pretty much anything at all because Python has a set of rules over how it converts values to booleans. More or less it is that: None, empty strings, lists etc , zero, are all False, anything else is True You can check by explicitly converting: spam = foo # or any other value print bool(spam) HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Boolean question
On Wed, Mar 16, 2011 at 12:22 AM, Donald Bedsole drbeds...@gmail.comwrote: not (False and True) Python evaluates it as True Is it because: 1)You evaluate what's in the parentheses first. A thing can not be false and true at the same time, so the answer is false. Yes, the expression in the parenthesis is evaluated first. However it's not just one thing being evaluated. 'and' evaluates one argument at a time and returns immediately if the argument is False. In this case there are 2 distinct 'things'. False and True. False, obviously, evaluates to False, which causes 'and' to stop and return False. This reduces the expression to... not False 2)However, the not outside the parentheses flips the meaning of what is inside the parentheses, so false becomes True. ? Correct, the expression not False evaluates to True. -- Jack Trades Pointless Programming Blog http://pointlessprogramming.wordpress.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor