Hack Forums
[Python] False and not True - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Python] False and not True (/showthread.php?tid=4725010)



False and not True - theChive - Mar 10, 2015

I am learning the basics of Python right now. I came upon this part of my homework:

Code
Bool_two = False and not True or True

I understand that "not" is evaluated prior to "and" which is evaluated prior to "or", but how does it work if the operations are side by side. I think of it like a math problem like "9 - + 10 + 1"
Is this a poor strategy?


* - Misingnoglic - Mar 10, 2015

Honestly you will NEVER see code like this in real life. You would want to put parentheses to make this very explicit. Python is really into explicit instead of implicit.

Anyway, I think the line is evaluated like this (False and (not True)) or True

not True is False, False and False is False, but False and True is True so the expression becomes True


* - Goodies - Mar 10, 2015

This is actually simple logic.

False and not True or True

Unfortunately, there are no parenthesis, so I'll just go left to right... This becomes:

False and False or True

The 'and' is only True if both sides are true. If one or both side(s) are false, it returns False. That being said, this becomes:

False or True

Which is obviously:

True


* - theChive - Mar 11, 2015

(Mar 10, 2015 09:32 PM)Goodies Wrote:  This is actually simple logic.

False and not True or True

Unfortunately, there are no parenthesis, so I'll just go left to right... This becomes:

False and False or True

The 'and' is only True if both sides are true. If one or both side(s) are false, it returns False. That being said, this becomes:

False or True

Which is obviously:

True

Thank you for your in depth response (and same to you, Misingnoglic).

Is "False and not True" really just "False and False" ?


* - lockhead - Mar 12, 2015

(Mar 11, 2015 02:40 PM)theChive Wrote:  Is "False and not True" really just "False and False" ?

Well in boolean logic you have two states: true or false, 1 or 0, yes or no,...

So if something is "not true" it has to be "false". Therefore, yes, "false and not true" becomes "false and false". Since "false and false" is redundant you can shorten it to just false.