+ 3
Can anyone explain in detail about Boolean logic - not
6 ответов
+ 6
There are a couple of boolean operators, which you use to create boolean expressions, which the evaluate to true or false.
Before getting into them, let's establish the following:
if(5>4)
This expression evaluates to true
Now then, boolean operators. Remember that they "link" two expressions or more
They are:
(will use C- like languages)
1. AND operator ( && )
Both inputs must be true
Example
if( 5>4 AND 6<8)
This evaluates to true, bcs both conditions are met.
if( 4+5<=10 && 1-1==1 )
This evaluates to false, even though one is true, the other one is false.
2. OR operator ||
Only one of the inputs must be true. The example above return true if we replace && with ||
Another ex:
a=3;
b=5;
if(a<b || a+b==8)
Evaluates to true, only one must be true, in this case both, that does not influence the result
3. The "NOT" operator ( ! )
Flips everything
if( !(1+1=2))
Evaluates to true at first, but ! negates it and turns it to false.
if(!("a"=="A"))
Evaluates to false at first, then true because of the !
+ 6
// In computing, a "NOT" portal is a inversor in which we reverse the booleans,
For example:
1 (start) => 0 (arrival)
0 (start) => 1 (arrival)
+ 4
In Python, a boolean expression returns either True or False.
So what is 'not True'? False.
And what is 'not False'? True.
5>4 -> True
not 5>4 -> False
+ 2
To understand Boolean logic I recommend you take a course in mathematics called Boolean Algebra
Where you will learning of the various logic gate and their output but is a demo
The Logical AND gate
Rules state if all is on it is on
AND gate true table
A|B|output
1 1 0
1 0 0
0 1 0
0 0 0
Where 0 means off and one means on
Logical NOT gate rule state
State if one input is off the output will be on
the NAND gate and many other as you learn you will understand their true and become a master of boolean Logic
0
Not operator is nothing if the statement is correct then the result is False and if it is wrong then the result is True
0
It checks on the things you defined
Just for example
a=1
b=2
a!=b (a not equals to b it returns true if the condition is true thats is 1 not equals to 2)