Consider the following. The first element in a list
is not int
a = [1, 2.0, 3, 4, 5.0, 9.9, "abc"]
a is int # this says "False"
a is not int is true is that
a is an integer, and
int is the integer type, a sort of template for creating integers. They are not the same object any more than
2 are the same object, or
"pumpkin" are the same object. And that's what
is tests for: whether two values are literally the same object.
In object-oriented programming we say that the integer
a is an instance of the
int type (or class, they are essentially synonyms). To express this in Python, use
isinstance(a, int). You could also use
type(a) is int. The advantage of
isinstance() is that it also detects when
a is an instance a type based on
int (called a subclass or subtype).