Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use _ _ dict__ in python

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report