Add a class member variable on the fly : Class Dict « Class « Python






Add a class member variable on the fly

Add a class member variable on the fly

class C1:
    x = 23
print C1.x                    

C1.y = 45
C1.__dict__['z'] = 67
print C1.x, C1.y, C1.z        

           
       








Related examples in the same category

1.Class constructor parameter: dictionaryClass constructor parameter: dictionary