+ 5

Is there any differences between 'is' and '==' if yes then what's the differences?

23rd Aug 2019, 4:57 AM
Prince Raj
Prince Raj - avatar
5 Antworten
23rd Aug 2019, 5:20 AM
Hatsy Rei
Hatsy Rei - avatar
+ 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
23rd Aug 2019, 5:24 AM
Kuri
Kuri - avatar
+ 4
Kuri, Hatsy Rei you mean 'is' need to assign first to treat as equal operator if this is true then what the actual use of 'is', is it really useful?
23rd Aug 2019, 5:32 AM
Prince Raj
Prince Raj - avatar
+ 3
This is somehow same as "equal" and "subset" property of set theory. Both have their own use.
23rd Aug 2019, 7:33 PM
Rudrankit Sharma
Rudrankit Sharma - avatar
+ 1
In simple explanation 'is' is related to object '==' is related to its value.
1st Sep 2019, 7:15 AM
husen
husen - avatar