To check if two operands are not equal python provides operator !=.
Let’s see an example of not equal to an operator on an integer variable.
#Use of operator not equal to
a= "3"
b= "4"
c = "4"
#If a is not equal to b then conditon will print true
print("a=",a,"b=",b,"\nResult of Not Equal to Operator is ",a!=b)
print("\n")
#if c equal to b then condition will print false as we are using not equal to operator
print(" b=",b,"c=",c,"\nResult of Not Equal to Operator is ",b!=c)
print("\n")
a= 3 b= 4
Result of Not Equal to Operator is True
b= 4 c= 4
Result of Not Equal to Operator is False
Similarly, we can apply not equal to an operator on a variable that contains string values.
!= Operator return value as True when the value of operands are different. If both operands are the same then Not Equal to the operator will return False.
#Let's See with String value
str1= "ethosspace.com"
str2= "google.com"
str3 = "google.com"
#If str1 is not equal to str2 then conditon will print true
print("str1=",str1,"str2=",str2,"\nResult of Not Equal to Operator is ",str1!=str2)
print("\n")
#if str3 equal to str2 then condition will print false as we are using not equal to operator
print(" str2=",str2,"str3=",str3,"\nResult of Not Equal to Operator is ",str2!=str3)
str1= ethosspace.com str2= google.com
Result of Not Equal to Operator is True
str2= google.com str3= google.com
Result of Not Equal to Operator is False