python - i have '__contains__' ,why error -


class a(object):     def a(self):         return true     __contains__=a  b=a() print 2 in b#why error 

__contains__ meant take argument. a doesn't accept argument.

the following example working __contains__:

>>> class a(object): ...     def a(self, item): ...         return true ...     __contains__=a ... >>> b=a() >>> print 2 in b true 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -