12 Answers
New Answer12 Answers
New AnswerAlso 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
Maine function of not is to reverse the output. If your result is true then not ture will give output false
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
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
You can use 'not' in the boolean logic just like '!= True' meaning if the statement is false.
Sololearn Inc.
535 Mission Street, Suite 1591Send us a message