Python Forum
Not understand the difference and there uses
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Not understand the difference and there uses
#1
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?
Reply
#2
== 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
Reply
#3
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
Reply
#4
Hi thanks for the response. Out of interest in what situation would you use the not 1==1 instead of 1 !=1?
Reply
#5
def isDigitIsOne(digit):
   return digit == 1 

a = 45

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


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020