Table of content

What does != mean in python?

The != operator is a comparison operator in python, compares values of two operands. It returns True if both the values are not equal else it returns False. It is defined as not equal to operator. The operands can be any object number, strings, lists, tuples, dictionaries, etc. The != operator returns a boolean value.

Example 1:

a = 3
b = 4
print("a != b:", a != b )
string1 = "apple" 
string2 = "apple"
print("string1 != string2 :", string1 != string2)

list_1= [1, 3, 5, 7]
list_2= [2, 4, 6, 8]
print("list_1 != list_2: ", list_1 != list_2)​

The output for the above code is

a != b: True
string1 != string2 : False
list_1 != list_2:  True

Example 2: To check if a number is odd.

num = int(input("Enter a number: "))
if (num % 2 != 0 ):
    print("Number is odd")
else:
    print("Number is even")

The output for the above code is

Enter a number: 5
Number is odd
0 results
Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions