Property: is a data or function element that belongs to an object
Classes have class methods, instance methods, static methods, class data properties (class variables), and instance data properties (instance variables).
Class properties: Include class methods and class variables that can be accessed through a class or instance and modified only by a class.
Instance properties: including instance methods and instance variables
classMyClass (object): Name='ANL' def __init__(self, Age): Self.age=Age @classmethoddefClass_method (CLS):Print "I ' m class method" defExample_method (self): Self.age= 20Print "I ' m a method, and age is%d", Self.age @staticmethoddefStatic_method ():Print "I ' m static method"
Using classes to access class variables
Myclass.name # results for ' Anl '
Using classes to modify class variables
' Delav ' pritn myclass.name # results for ' Delav '
Utility classes to access class methods
Myclass.class_method () # result for I ' m class method
Using classes to access static methods
Myclass.static_method () # result for I ' m static method
modifying instance variables
# instantiation of print ob.age # results forob.age = # to Modify instance Properties Print Ob.age # Results of
Using instances to access class variables
print ob.name # results for ' Delav '
Using instances to access instance methods
Ob.example_method # results for I ' m example method, and age is
Using instances to access class methods
Ob.class_method () # result for I ' m class method
Using instances to access static methods
Ob.static_method () # result for I ' m static method
Modify instance properties, class variables unchanged, instance variables changed
' Bon ' Print Myclass.name # results for Delavprint ob.name # result for Bon
Total Results
Python object-oriented-class properties and instance properties