Skip to content

Instantly share code, notes, and snippets.

@AntiKnot
Created April 2, 2020 05:31
Show Gist options
  • Select an option

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

Select an option

Save AntiKnot/c0011670d4332323ec0dfdf10a3bcb1f to your computer and use it in GitHub Desktop.
类计数
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