__dict__()用法

 

dict: 类与对象的所有成员; 
类输出的是全局的函数,变量等信息。 
对象输出的只是对象拥有的普通变量而已

class Province:
    country = 'China'

    def __init__(self, name, count):
        self.name = name
        self.count = count

    def func(self, *args, **kwargs):
        print 'func'

print Province.__dict__
obj1 = Province('HeBei', 10000)
print obj1.__dict__
obj2 = Province('HeNan', 3888)
print obj2.__dict__

 

{'country': 'China', '__module__': '__main__', 'func': <function func at 0x1074191b8>, '__init__': <function __init__ at 0x1074190c8>, '__doc__': None}
{'count': 10000, 'name': 'HeBei'}
{'count': 3888, 'name': 'HeNan'}

 

 

 

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qianguozheng/article/details/50390156

 

 打印结果

 

posted on 2018-04-16 17:16  王大拿  阅读(239)  评论(0)    收藏  举报

导航