Advertisement



< Prev
Next >



Python - Relational Operators










This operator is also known as not equal to operator. It compares the values of its two operands by checking for their inequality. It returns a boolean value true when operands have unequal values otherwise it returns false.




A coding example with != operator


# Python != operator example

if 'z' != 'a' : 		#comparing a character to another character
    print("z is not equal to a")


if 100 != 100.001 :		#comparing an integer with a floating value
    print("100 is not equal to 100.001")


if 99.9999 != 99.999 :		#comparing a floating value with a floating value
    print("99.9999 is  not equal to 99.999")


if 5.00 != 5.0 :		#comparing an integer to floating value
    print("5.00 is not equal to 5.0")

	
if 11 !=10 :			#comparing an integer to an integer
    print("11 is not equal to 10")

	
if 98 != 'hello' :		# A string in python can be compared to another value only using == operator.
    print("98 is not equal to a")


Output -


z is not equal to a
100 is not equal to 100.001
99.9999 is  not equal to 99.999
11 is not equal to 10
98 is not equal to a
Note : There should never be any space between ! and = of != operator, or a compile error is thrown.



Please share this article -





< Prev
Next >
< Python compound assignment operators
Python logical operators >



Advertisement

Please Subscribe

Please subscribe to our social media channels for daily updates.


Decodejava Facebook Page  DecodeJava Twitter Page Decodejava Google+ Page




Advertisement



Notifications



Please check our latest addition

C#, PYTHON and DJANGO


Advertisement