Python中可不可以获取到某个类有多少个实例
展开全部
class A(object):
count = 0
def __init__(self):
A.count += 1
Python 3.6.1 (default, Mar 22 2017, 06:17:05)
[GCC 6.3.0 20170321] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> class A(object):
... count = 0
... def __init__(self):
... A.count += 1
...
>>> a = A()
>>> a.count
1
>>> b = A()
>>> b.count
2
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询