Here is my code:
if self.d:return True
print b.contains('d') # error
print contains(b,'d') # error
Like all special methods (with "magic names" that begin and end in
__contains__ is not meant to be called directly (except in very specific cases, such as up=calls to the superclass): rather, such methods are called as part of the operation of built-ins and operators. In the case of
__contains__, the operator in question is
in -- the "containment check" operator.
With your class
a as you present it (except for fixing your typo, and using
True instead of
b as its instance,
print 'x' in b will print
True -- and so will any other containment check on
b always returns
self.d, a non-empty string, is true).