Test for object identity should be
Testing the identity of two objects can be achieved in python with a special operator called
Most prominently it is used to check whether an variable points to
But the operator can examine any kind of identity.
This often leads to confusion because equality of two different objects will return
a = range(10) b = range(10) print((a is b))
This code snippet will print
False even though
b have equal values.
This can occur because
b are references that point to different objects which happen to have the same value.
To verify the equality of two variables the
== operator should be used.
Only use the
is operator if you want to check the exact identity of two references.
some_list = None if some_list is None: do_somthing_with_the_list()