Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use _ _ dict__ in python

Shulou Source: shulou.com Published: 2022-06-03 15:18:12 10月04日 Update

This article mainly introduces how to use__dict__in python. The introduction in the article is very detailed and has certain reference value. Interested friends must read it!

__dict__is an attribute, not a method.

If__dict__is called using an instance object, a dictionary consisting of all instance attributes is output.

Calling__dict_with a class object will output a dictionary consisting of all instance methods, class attributes, and class methods.

examples

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("Little Pineapple")blog.test()#Instance object calls print(blog.__ dict__) #class object calls print(PoloBlog.__ dict__) #Output results {'name': 'Little Pineapple'}{'__module__': '__main__', 'sum': 0, '__init__': , 'test':, 'test_cls': ,'test_static':, '__dict__': , '__weakref__': , '__doc__': None} The above is "How to use__dict__in python" all the content of this article, thank you for reading! Hope to share the content to help everyone, more relevant knowledge, welcome to pay attention to the industry information channel!

Tags: Examples objects properties methods outputs content dictionaries articles pineapples values interests guys buddies more knowledge results industry information information channels channels Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei OPPO Reno MySQL vpn MariaDB