python __dict__的使用注意

python __dict__的使用注意

1、__dict__是属性,不是方法。

2、若使用实例对象调用__dict__,则输出由所有实例属性组成的字典。

3、用类对象调用__dict__将输出由所有实例方法、类属性和类方法组成的字典。

实例

class PoloBlog:
    sum = 0
 
    def __init__(self, name):
        self.name = name
 
    def test(self):
        pass
 
    @classmethod
    def test_cls(cls):
        pass
 
    @staticmethod
    def test_static():
        pass
 
 
blog = PoloBlog("小菠萝")
blog.test()
# 实例对象调用
print(blog.__dict__)
 
# 类对象调用
print(PoloBlog.__dict__)
 
 
# 输出结果
{'name': '小菠萝'}
{'__module__': '__main__', 'sum': 0, '__init__': <function PoloBlog.__init__ at 0x105d2b0d0>, 'test': <function PoloBlog.test at 0x105d4d310>, 'test_cls': <classmethod object at 0x105c47fa0>, 'test_static': <staticmethod object at 0x105c47d90>, '__dict__': <attribute '__dict__' of 'PoloBlog' objects>, '__weakref__': <attribute '__weakref__' of 'PoloBlog' objects>, '__doc__': None}


微信扫描下方的二维码阅读更多精彩内容

python __dict__的使用注意

每日分享到群里,或者推荐给朋友会得大量积分,机会可以兑换微信零钱红包,具体请点击这里,得到了微信红包可以用来支持大飞哥

大飞哥能不能加鸡腿就看各位了!

赞赏请扫

开发者微信

大飞哥微信

开发者微信反馈BUG或者VIP可以添加,其他情况反馈可能不及时,见谅

版权声明

初衷是提供高清手机电脑壁纸等图片素材免费分享下载,禁止商用。图片素材来源网络,版权归原作者所有,若有侵权问题敬请告知我们!

【友情提醒】:

因平台原因不易展示大尺度写真,有的写真展示越少代表此套写真越性感,特别是xiuren等写真每一套写真完整套图50-100张不等。更多内容的欣赏请移步 点击这里

【更多图集移步】: 每日更新-点击这里
漂亮小姐姐-点击这里
性感美女-点击这里
清纯女孩-点击这里
xiuren专栏-点击这里
整站资源下载-点击这里

相关新闻