Identity operators compare the memory addresses of objects to check if two variables reference the same object. They return True if they reference the same object, otherwise False.
【Excel VBA】
In Excel VBA, use Is to check if two variables reference the same object, and IsNot to check if they reference different objects. The sample file path is Samples\ch03\Excel VBA\Identity Operators.xlsm.
code.vba
Sub Test7()
Dim objA As Object
Dim objB As Object
Dim objC As Object
Set objA = objC
Set objB = objC
Debug.Print objA Is objB ' True(both reference objC)
End Sub
Running the procedure outputs True in the Immediate Window.
【Python】
In Python, use is or is not to check if two variables reference the same object:
code.python
>>> a = 10; b = 20
>>> a is b # False(different objects)
>>> a = 10; b = a
>>> a is b # True(same object)