Python "is" statement: what is happening? [duplicate]
a is not b
is a special operator which is equivalent to not a is b
.
The operator a is b
returns True if a and b are bound to the same object, otherwise False. When you create two empty lists you get two different objects, so is
returns False (and therefore is not
returns True).
is
is the identity comparison.
==
is the equality comparison.
Your statement is making two different lists and checking if they are the same instance, which they are not. If you use ==
it will return true and because they are both empty lists.