#小练习 类属性 分类: 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__)
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 '**********help(d.__class__)**********'
print help(d.__class__)
相关文章推荐
- 深拷贝与浅拷贝的练习 分类: python 小练习 2013-10-29 16:29 284人阅读 评论(0) 收藏
- #小练习 输出两个数的最大公约数 分类: python 小练习 2013-11-08 11:16 385人阅读 评论(0) 收藏
- 使用类、类属性、对象属性 分类: python基础学习 2014-03-19 16:22 220人阅读 评论(0) 收藏
- 输出文件中不包含指定的多个排除词的行内容(双重遍历) 分类: python 小练习 2013-11-22 15:20 605人阅读 评论(0) 收藏
- 翻转列表项 分类: python 小练习 2013-06-15 14:52 239人阅读 评论(0) 收藏
- SGMLParser (二) 分类: python 小练习 HTMLParser 2014-02-20 14:06 362人阅读 评论(0) 收藏
- 去除列表中不重复的元素 分类: python 小练习 2013-06-25 14:59 245人阅读 评论(0) 收藏
- 最大公约数 分类: python 小练习 2013-12-02 11:00 222人阅读 评论(0) 收藏
- # 输出目录下的文件 os模块 分类: python 小练习 2013-05-13 18:01 205人阅读 评论(0) 收藏
- #遍历E盘下的mp3文件 分类: python 小练习 python 2013-05-14 18:27 303人阅读 评论(0) 收藏
- python发送各类邮件的主要方法 分类: python Module python 小练习 2014-01-14 14:52 310人阅读 评论(0) 收藏
- 数字排序,波动增长 分类: python 小练习 2013-07-04 19:01 281人阅读 评论(0) 收藏
- #小练习 冒泡排序 分类: python 小练习 2013-05-03 14:36 200人阅读 评论(0) 收藏
- 结尾非零数的奇偶性 分类: python 小练习 2013-12-02 18:04 371人阅读 评论(0) 收藏
- #小练习 异常 分类: python异常 python 小练习 2013-05-14 13:35 452人阅读 评论(0) 收藏
- 使用super()继承 分类: python 小练习 2013-09-18 14:13 320人阅读 评论(0) 收藏
- 将两个列表元素组成字典 分类: python 小练习 2013-11-12 18:17 750人阅读 评论(0) 收藏
- 判断元素出现的次数、总和 分类: python 小练习 2014-03-21 15:52 250人阅读 评论(0) 收藏
- 使用文件进行优化 分类: python 小练习 divide into python python基础学习 2014-01-01 14:13 228人阅读 评论(0) 收藏
- #小练习 pickle模块_分别存储python对象 分类: python Module 2013-09-05 18:07 379人阅读 评论(0) 收藏