Friday, 4 December 2015

Identity operators in python

Identity operators are used to compare the memory locations of two objects.

Operator
Description
is
a is b returns true, if both a and b point to the same object, else false.
is not
a is not b returns true, if both a and b not point to the same object, else false.


>>> name1="Hari Krishna"
>>> name2=name1
>>> name3="Hari Krishna"
>>> name4="abc"
>>> 
>>> name1 is name2
True
>>> name1 is name3
False
>>> name1 is name4
False
>>> name1 is not name3
True






Previous                                                 Next                                                 Home

No comments:

Post a Comment