Generates a class attribute : Class fields : Class PYTHON examples


PYTHON examples » Class » Class fields »

 

Generates a class attribute


Generates a class attribute
 

class SharedData:
     spam = 42                    # generates a class attribute

x = SharedData()                  # make instances
y = SharedData()
print x.spam, y.spam              # they inherit and share spam

SharedData.spam = 99
print x.spam, y.spam, SharedData.spam


x.spam = 88
print x.spam, y.spam, SharedData.spam

           
         
  



Leave a Comment / Note


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


PYTHON examples

 Navioo Class
» Class fields