Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python __dict__

# __dict__
class A:
    class_var = 1
    def __init__(self) -> None:
        self.a = 2
        self.b = 3

a = A()
print(a.__dict__.items())       
# dict_items([('a', 2), ('b', 3)])
print(A.__dict__.items())
# dict_items([('__module__', '__main__'), ('class_var', 1), 
# ('__init__', <function A.__init__ at 0x00000197277BE320>), 
# ('__dict__', <attribute '__dict__' of 'A' objects>), 
# ('__weakref__', <attribute '__weakref__' of 'A' objects>), ('__doc__', None)])
Source by localhost #
 
PREVIOUS NEXT
Tagged: #python
ADD COMMENT
Topic
Name
2+6 =