Created
April 2, 2020 05:31
-
-
Save AntiKnot/c0011670d4332323ec0dfdf10a3bcb1f to your computer and use it in GitHub Desktop.
类计数
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 Foo: | |
| count = 0 | |
| def __init__(self, a: int): | |
| self.a = a | |
| self.add1() | |
| @classmethod | |
| def add1(cls): | |
| cls.count += 1 | |
| if __name__ == '__main__': | |
| baba = Foo | |
| a = Foo(1) | |
| assert baba.count == 1 | |
| b = Foo(1) | |
| assert baba.count == 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment