Class instance value setting : Class Definition : Class PYTHON examples


PYTHON examples » Class » Class Definition »

 

Class instance value setting


 

class Foo :
   x = 1


f1 = Foo()
f2 = Foo()
print f1.x
print f2.x
f1.__class__.__dict__['x'2
print f1.x
print f2.x

f3 = Foo()
print f3.x
f3.x = 3
print f2.x
print f3.x

if f2.x == f2.__class__.__dict__['x':
    print "No change"
if f3.x == f3.__class__.__dict__['x':
       print "No change"
else :
       print "Value changed"

   
  



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON examples

 Navioo Class
» Class Definition