yasoob/intermediatePython

Add a cool trick, the __contains__ function

Closed this issue · 1 comments

you may also be interested to know that what in does is to call the list.contain method, that you can define on any class you write and can get extremely handy to use python at it's full extent.

>>> class ContainsEverything:
    def __init__(self):
        return None
    def __contains__(self, *elem, **k):
        return True


>>> a = ContainsEverything()
>>> 3 in a
True
>>> a in a
True
>>> False in a
True
>>> False not in a
False
>>> 

I am sorry for taking so long to respond. Can you provide a useful use-case for this?