Integers are some of the simplest data types in Python. It's one of the first things we ever learn:
a = 3
The variable a is equal to 3. Simple, right?
...right?
Let's try something in our Python interpreter.
>>> a = 256
>>> b = 256
>>> a != b
False
Phew, so far so good. Let's now play around with the is operator.
is OperatorThe is operator is very similar to the == operator, except that it compares equality between objects instead of between the values that the object holds. Let's take a simple list example to demonstrate this:
>>> a = [1, 2, 3]
>>> b = [1, 2, 3]
>>> a == b
True
>>> a is b
False
Notice how, because the values of a and b are equal, they are == to each other. However, since a and b are created separately and independently, they are not the same object. Thus, a is equal to be but a is not b.