您的位置:首页 > 编程语言 > Python开发

#小练习 类属性 分类: python 小练习 2013-04-28 14:46 190人阅读 评论(0) 收藏

2013-04-28 14:46 525 查看
class counter:

count = 0

def __init__(self):

self.count+=1

class counter2:

count = 0

def __init__(self):

self.__class__.count+=1

print counter.count # 类的属性

b=counter() # instance of class counter

print b.count

c=counter() # instance of class counter

print c.count

# 比较一下 self.__class__.count 与 self.count 结果的区别

d=counter2() # instance of class counter

print d.count

e=counter2() # instance of class counter

print d.count

print '**********help(b.__class__)**********'

print (b.__class__)

print

print '**********help(d.__class__)**********'

print help(d.__class__)

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐