首页 > 编程语言 > 详细

Python3.7之类的属性

时间:2020-01-17 12:27:38      阅读:81      评论:0      收藏:0      [点我收藏+]

一、__dict__

程序使用 __dict__ 属性既可查看对象的所有内部状态,也可通过字典语法来访问或修改指定属性的值。

class A:

    a = 1
    b = 2

    def __init__(self):
        self.c = 3
        self.d = 4

    def test1(self):
        pass

    @classmethod
    def test2(self):
        pass

    @staticmethod
    def test3():
        pass


A_1 = A()
print(A_1.__dict__)
print(A.__dict__)

'''
{'c': 3, 'd': 4}
{'__module__': '__main__', 'a': 1, 'b': 2, '__init__': <function A.__init__ at 0x00000149BE8396A8>, 'test1': <function A.test1 at 0x00000149BE839730>, 'test2': <classmethod object at 0x00000149BE831B38>, 'test3': <staticmethod object at 0x00000149BE831B70>, '__dict__': <attribute '__dict__' of 'A' objects>, '__weakref__': <attribute '__weakref__' of 'A' objects>, '__doc__': None}
'''

由此可见, 类的静态函数、类函数、普通函数、全局变量以及一些内置的属性都是放在类__dict__里的

对象的__dict__中存储了一些self.xxx的一些东西

Python3.7之类的属性

原文:https://www.cnblogs.com/rainbow-ran/p/12204916.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!