0

Ok so below this paragraph is a chart that I attempted to copy over to here to assist me with explaining my problem. I am doing a course to teach myself Python programming. mid-way through the course I encounter a lesson on 'Booleon Logics'and the chart below is in the lesson.
I understand the simple ones like:
-'not False' "True"
-'True or True' "True"
But then I approach some that make no sense to me:
-'True and False' "False"----Why?
-'True or False' "True"-----How?

How is that conclusion made? There has got to be something im missing here. I realize I could just go ahead and memorize the chart but there has got to be a reasoning that will help me understand.

NOT True?

not False True

not True False

OR True?

True or False True

True or True True

False or True True

False or False False

AND True?

True and False False

True and True True

False and True False

False and False False

NOT OR True?

not (True or False) False

not (True or True) False

not (False or True) False

not (False or False) True

NOT AND True?

not (True and False) True

not (True and True) False

not (False and True) True

not (False and False) True

!= True?

1 != 0 True

1 != 1 False

0 != 1 True

0 != 0 False

== True?

1 == 0 False

1 == 1 True

0 == 1 False

0 == 0 True

  • Also see [the documentation on this](https://docs.python.org/3/library/stdtypes.html). – TigerhawkT3 Dec 13 '16 at 06:00
  • @TigerhawkT3: respectfully, I don't think that's an appropriate dupe at all. The question sounds to me like the OP doesn't understand basic Boolean logic, which is an entirely different discussion than short circuiting. – Mac Dec 13 '16 at 06:29
  • @Mac - I believe it is appropriate. Read this question more closely and you will see that the OP says that the simpler expressions are clear, while things like `True and False` producing `False` are not. That is short-circuiting, which is what the linked duplicate answers. Besides, a tutorial in discrete mathematics would not be in the scope of SO. – TigerhawkT3 Dec 13 '16 at 07:45
  • @TigerhawkT3: I'm sorry, I really don't agree. The result `True and False -> False` is a pretty fundamental result of Boolean algebra, and holds whether `and` is short-circuited or not. It should be crystal clear with only a basic understanding of Boolean algebra (and none of the specifics of how it is implemented in Python) why that identity holds. If the OP can't understand that result it is because they have a misunderstanding of the math, not of short-circuiting. That said, I agree that this probably isn't the place for a crash-course in the math. – Mac Dec 13 '16 at 22:35
  • @Mac - The important part here is that in `True or False`, the `False` _is never evaluated_ and the first operand is returned, which, in addition to explaining the various results here, makes a difference when the simple Boolean values are replaced with other objects, like strings or function calls. The duplicate link explains how this process works in Python. – TigerhawkT3 Dec 13 '16 at 23:11
  • @TigerhawkT3: let me put it another way: if `and` *wasn't* short circuited, would the answer be different? No, `True and False` would still be `False`. You don't need to know *anything* about short circuiting to understand that `True and False -> False`, which implies the OP's problem is with the basic logic of `and`, not with short-circuiting. I agree that understanding short circuiting is important in almost all circumstances beyond the trivial, but at this stage it's just a distraction. This is, of course, just my interpretation - I'm happy to be proven wrong if the OP decides to clarify. – Mac Dec 13 '16 at 23:31
  • Mac is right. I didn't have any understanding on boolean logic and the math. I was asking 'why' it was that way. I am new to Python and basically to any programming outside of web developement (html, css and very basic javascript), but I am grasping it now, if one of you guys have any links to a useful article so I could learn more that would be helpful; otherwise, I am going to read up on this short-circuiting and if thats what I was asking I'll come back and say so, otherwise assume its not. – Creeping-spyder Jan 29 '17 at 18:41

0 Answers0