Skip to content

Instantly share code, notes, and snippets.

@AntiKnot
Created June 2, 2020 03:13
Show Gist options
  • Select an option

  • Save AntiKnot/5a93b79c8f15be129ad847ae63b004ec to your computer and use it in GitHub Desktop.

Select an option

Save AntiKnot/5a93b79c8f15be129ad847ae63b004ec to your computer and use it in GitHub Desktop.
python magic methods
class B:
pass
class A:
def __init__(self,bs):
self.bs=bs
def __contains__(self, item):
if isinstance(item,B):
return item in self.bs
@AntiKnot
Copy link
Copy Markdown
Author

AntiKnot commented Jun 2, 2020

contains 方法用来实现in这个协议

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment