Skip to content

Instantly share code, notes, and snippets.

@JakeTheCorn
Created June 25, 2020 22:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JakeTheCorn/92902b1d7d5a530f8ba3c065fba3e7f0 to your computer and use it in GitHub Desktop.
Save JakeTheCorn/92902b1d7d5a530f8ba3c065fba3e7f0 to your computer and use it in GitHub Desktop.
# the in operator looks in a class's __contains__ method
class A:
def __init__(self, numbers=[]):
self.__numbers = numbers
def __contains__(self, item):
return item in self.__numbers
a = A(numbers=[1, 2, 3])
print(3 in a)
print(4 in a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment