Created
June 2, 2020 03:13
-
-
Save AntiKnot/5a93b79c8f15be129ad847ae63b004ec to your computer and use it in GitHub Desktop.
python magic methods
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
contains 方法用来实现in这个协议