Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

False and not True

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?
Keep calm, chive on.
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
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
SRPP Discord Server

I am a professional network/cloud security architect.
My Old Tutorials
(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" ?
Keep calm, chive on.
(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.
[Image: 0DvFxnA.gif]
Donate: 3ABKRghau93ziRaDfVwiiwtjky3i1gLrKn


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by thibautSep 13, 2015 06:53 AM 5 163 Sep 13, 2015 06:53 AM
Last Post: thibaut
[.NET] by BrokeosDec 24, 2013 07:09 AM 16 363 Dec 24, 2013 07:09 AM
Last Post: Brokeos
[Python] by clark.dllJun 9, 2013 10:41 PM 6 129 Jun 9, 2013 10:41 PM
Last Post: clark.dll