Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

__dict__ python?

class DogClass:
    def __init__(self,name,color):
        self.name = name
        self.color = color
    
    def bark(self):
        if self.color == "black":
            return True
        else:
            return False
dc = DogClass('rudra','white')
print(dc.__dict__)
# Output: {'name': 'rudra', 'color': 'white'}

DogClass.__dict__
Comment

__dict__

shared variable
{'__module__': '__main__', 'class_var': 'shared variable', '__dict__': <attribute '__dict__' of 'Demo' objects>, '__weakref__': <attribute '__weakref__' of 'Demo' objects>, '__doc__': None}
Comment

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)])
Comment

PREVIOUS NEXT
Code Example
Python :: python keyword arguments 
Python :: Python RegEx Subn – re.subn() Syntax 
Python :: python how to create a class 
Python :: start virtualenv with python version 
Python :: python minimum 
Python :: what is print in python 
Python :: import os in python 
Python :: if or python 
Python :: positional only arguments python 
Python :: multivaluedictkeyerror django 
Python :: how to slice list 
Python :: concatenate strings and int python 
Python :: python get the last in dictionary 
Python :: python print text 
Python :: depth first search 
Python :: append to a tuple 
Python :: doing some math in python 
Python :: python and flask create_app 
Python :: self object 
Python :: count function in python 
Python :: # keys in python 
Python :: class object 
Python :: signup 
Python :: python array empty 
Python :: new line eval python 
Python :: pathlib is symbolic link 
Python :: Python - Comment supprimer Commas de la corde 
Python :: arcpy line density 
Python :: summation 
Python :: destroy trigger python 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =