Python Forum

Full Version: Not understand the difference and there uses
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi All

Just need help understand the difference between using the below 2 syntax.

Input: not 1 == 1
Output: False

Input: 1 != 1
Output: False

Please note that output and input are not part of the code.

They both give you the exact same results and in essence are saying thing. In what circumstance would you use the one over the other?
== and != are operators of equality.
not is a logical operator that revers the value of a logical variable.

For understanding a difference just try to change "==" to "is_equal" and "!=" to "is_not_equal" functions.

def is_equal(a, b):
    return a == b

def not_is_equal(a, b):
    return a != b
not 1 == 1 are actually two actions
first 1 == 1 is evaluated, which is True
and then the True is negated with the not operator
Hi thanks for the response. Out of interest in what situation would you use the not 1==1 instead of 1 !=1?
def isDigitIsOne(digit):
   return digit == 1 

a = 45

if not isDigitIsOne(a):
    print("False")