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 equal else it returns False. The operands can be any object number, strings, lists, tuples, dictionaries, etc. The == operator returns a boolean value.

Example,

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

list_1= [2, 4, 6,8]
list_2= [2, 4, 6,8]
print("list_1==list_2: ", list_1 == list_2)​

Output

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

If == operator is used to assign variable before definition, then it throws a NameError exception. In the below example, num was assigned to a variable 3 by using == operator and the code throws an error.

num == 3

Output

    num == 3
NameError: name 'num' is not defined
0 results
Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions