发布时间:2022-12-10 09:31:38 人气:92 作者:多测师
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__': , 'test': , 'test_cls': , 'test_static': , '__dict__': , '__weakref__': , '__doc__': None}
以上就是python __dict__的使用注意,希望对大家有所帮助。更多Python学习指路:请关注多测师。https://www.e70w.com/xwzx/