Identity operator in python are used to check the object identity of two operands which doesn’t mean equality (==). We use ‘is’ and ‘is not’ operator. Actually, Identity operators compare the same operands with same memory locations. Two variables that are equal does not imply that they are identical. Lets understand it with example:
>>> a = 5
>>> b = 5
>>> print ("a is b :",a is b, " a == b :", a==b)
>>> c = {5,4}
>>> d = {5,4}
>>> print ("c is d :",c is d, " c == d :", c==d)
>>> print ('c is not d :', c is not d)
OUTPUT:
a is b : True a == b : True
c is d : False c == d : True
c is not d : True
In the above example, we see that a and b are integers of same values, so they are equal as well as identical. But c and d are sets. They are equal but not identical. It is because interpreter locates them separately in memory although they are equal in identity operator in python.
This page is contributed by Diwas & Sunil . If you like AIHUB and would like to contribute, you can also write an article & mail your article to itsaihub@gmail.com . See your articles appearing on AI HUB platform and help other AI Enthusiast.
whoah this weblog is magnificent i really like studying your posts.
Stay up the great work! You realize, a lot of individuals are hunting round for this info, you can help them greatly.
adreamoftrains web hosting services
Attractive section of content. I just stumbled upon your website and in accession capital to assert that I get in fact enjoyed account your blog posts.
Any way I will be subscribing to your feeds and even I achievement you access consistently rapidly.