How to use the "not" in the boolean logic ? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
+ 4

# How to use the "not" in the boolean logic ?

23rd May 2019, 8:18 AM
Tanmay Maheshwari
15 Réponses
+ 6
Use the "not" keyword (not False = True)
23rd May 2019, 8:22 AM
Airree
23rd May 2019, 9:02 AM
Sonic
+ 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
20th May 2021, 11:23 AM
Niederkofler Martin
+ 3
If you are using C-like programming languages, use ! (Example: !false = true)
23rd May 2019, 8:20 AM
Airree
+ 2
Hh
3rd Jul 2021, 3:22 PM
Hamza Rahali
+ 2
Maine function of not is to reverse the output. If your result is true then not ture will give output false
29th Sep 2021, 4:19 PM
Rishav Kumar
22nd Nov 2021, 7:08 PM
✓`•°`™AnOnimus™`°•`✓ فايز الله‎
12th Apr 2022, 7:25 PM
✓`•°`™AnOnimus™`°•`✓ فايز الله‎
+ 1
In python how to use it.?
23rd May 2019, 8:21 AM
Tanmay Maheshwari
+ 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
12th Apr 2021, 7:26 AM
shubham damania
+ 1
You can use 'not' in the boolean logic just like '!= True' meaning if the statement is false.
5th May 2021, 2:26 PM
Lemi Elias
+ 1
you use not for not intend of the list
12th Apr 2022, 1:06 PM
Jena
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
30th Jul 2022, 10:12 AM
Israel Mutebi
0
You can use 'not' in the boolean logic just like '!= True' meaning if the statement is false.
23rd Aug 2022, 4:37 PM
Shivansh Srivastava
0
There is a short way: Use the ! Symbol instead of using Not, Like: If (2 != 2): Or If (not ( 2 == 2)):
24th Sep 2022, 8:41 AM
Yousef Yousefzai
Aujourd'hui en vedette
c++ help