Conditions operators like >,<,<=, >=, in, not, etc. are used to produce boolean expressions which are useful for example for testing in
if
statements. In the first example, we use those operators to compare two integers. Since the values are compared, so if the expression is True, the answer is always True. Equality is represented by == and is used to test whether two values are the same. In the example above, since the values are the same, the answer is true.
However, there is another testing operator called
is
which is the identity testing. This operator tests whether two objects are the same, not their values. In analogy, to another language like C, this operator would test if two objects have the same pointers. In the example, [1,2] and [1,2] have the same values, but are not the same objects: they are two different list objects which are created independently. So, the test fails and returns False. However, a=[1,2,3] and b=a is always True because both variables point to the same object which is the list [1,2,3] which was created only once.
In the last example, 1 is 1 is sometimes true because there is no guarantee in Python that two integers or two strings are represented by the same object. In Python, immutable objects like integers or strings are not guaranteed to be unique unlike in some other object languages (ex. some Smalltalk implementations).