+ 4
How to use the "not" in the boolean logic ?
15 Réponses
+ 6
Use the "not" keyword (not False = True)
+ 4
Also correct is
A = 1
B = 2
if (not (A == B)):
print("A and B are >>not<< equal!")
else:
print("A and B are equal.")
The above syntax is to read more clearly, you need to be aware of closing an opening braces to avoid bracing errors, though, which sometimes may lead in undefined behavior.
Sometimes it just leads to more readable code like above, though, imagine a function/program returning either False/True
def checkIfTrue:
# some code checking something
# ...
return False
Now you can either wrap your lines within a if statement
if (checkIfTrue):
# continue with the program
else:
exit
or just save one indentation level
if (not (checkIfTrue)):
exit
# continue with the program
+ 3
If you are using C-like programming languages, use ! (Example: !false = true)
+ 2
Hh
+ 2
Maine function of not is to reverse the output. If your result is true then not ture will give output false
+ 2
https://code.sololearn.com/WfGsuo7ScpN2/?ref=app
https://code.sololearn.com/cL1lrvvd1bzR/?ref=app
https://code.sololearn.com/c6F630J0Wfrn/?ref=app
https://code.sololearn.com/WyGVxB72ADIo/?ref=app
https://code.sololearn.com/cv3ZTXQJlzt7/?ref=app
https://code.sololearn.com/WM1AasOTNp2j/?ref=app
https://code.sololearn.com/cH3K0Ez7a3Hh/?ref=app
https://code.sololearn.com/WE8M5X2BBIPU/?ref=app
https://code.sololearn.com/WFtEn738d971/?ref=app
https://code.sololearn.com/cvLJyJcT2615/?ref=app
+ 1
In python how to use it.?
+ 1
The not operator is an inverter meaning the condition followed by the operator is inverted
Eg
Print (not True)
This will return false
And since it is used to invert, its an unary operator, i.e it takes only one condition
+ 1
You can use 'not' in the boolean logic just like '!= True' meaning if the statement is false.
+ 1
you use not for not intend of the list
0
I know that A != B
A =1
B=2
not (A==B) is the same as
A ! =B
The answer is the same, True
0
You can use 'not' in the boolean logic just like '!= True' meaning if the statement is false.
0
There is a short way:
Use the ! Symbol instead of using Not, Like:
If (2 != 2):
Or
If (not ( 2 == 2)):