is and == in Python

The is keyword tests whether two variables point to the same object. In other words this code:

a is b

Tests whether:

a.id() == b.id()

The == operator tests whether two objects have the same value. The meaning of this depends upon the type of the object.
It is defined in the obvious way for built-in types.

You can make your own types comparable with == by implementing __eq__():

class C(object):
    def __init__(self, val):
        self.val = val

    def __eq__(self, other):
        return self.val == other.val

c = C('spam')
d = C('spam')
print c == d
True

Note that because Python will cache and reuse object instances, two different objects that compare equal with == may also compare equal with is, but this should not be relied upon.