The ‘is’ operator compares the identity (memory location) of two objects while the ‘==’ operator compares the values of two objects.

The ‘==’ operator return True when the values of two operands are equal and false otherwise.

print(True == 1) 
# True means 1 (Python convert the boolean 'True' into integer 1) so True == 1 means 1 == 1

print('1' == 1) 
# '1' means string one and 1 means integer one, in python two different types are not comparable 

print([] == 1) 
# Empty list can't be equal to one

print(10 == 10.0) 
# Python can convert integer and float number, here Python convert them in the same type

print([1,2,3] == [1,2,3]) 
# I hope you understand it

Return

True
False
False
True
True

The ‘is’ operator return True if the variables on either side of the operator point to the same object (same memory location) and false otherwise.

print(True is 1) 
print('1' is 1)
print([] is 1)
print(10 is 10.0)
print([1,2,3] is [1,2,3])
# in all examples both side of 'is' are in the difference location in memory (they are not identical) or you can say they are not same.

Return

False
False
False
False
False

Tags: