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

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__)

版权声明:本文为博主原创文章,未经博主允许不得转载。

posted @ 2013-04-28 14:46  前行者2011  阅读(109)  评论(0编辑  收藏  举报