+ 5
Is there any differences between 'is' and '==' if yes then what's the differences?
5 Antworten
+ 5
'==' & 'is' operators are different.
The == operator compares the values of both the operands and checks for value equality. Whereas, is operator checks whether both the operands refer to the same object or not.
U can use id() to check whether both the operands refer to the same object (i. e. memory location) or not.
Ex - list1=[1, 2,3]
list2=[1, 2,3]
list1=list3
list3 is list1 - True .
But, list2 is list1- False
+ 3
This is somehow same as "equal" and "subset" property of set theory.
Both have their own use.
+ 1
In simple explanation
'is' is related to object
'==' is related to its value.