ImportOS#Os.system ()#Os.mkdir ()classDog (object):#name = ' KK ' def __init__(self,name): Self.name=name#@staticmethod #静态方法, it's really nothing to do with the class, and it's not going to take the self argument. #@classmethod #类方法, the self parameter can be called, but the instantiated variable cannot be called. @property#static properties, cannot pass in parameters, can only invoke the properties of the class or instance itself. defEat (self):Print("%s is eating%s"% (Self.name,'DD')) defTalk (self):Print("%s is talking"%self.name) d= Dog ("Chenronghua") D.eatd.talk ()
Class
Variable
class variables
Instance variable
Private variables
Method
constructor function
Destructors
Private methods
Object
Instantiate a class and then get an object
Packaging
Hide the implementation details of some features
Inherited
Re-use code
Single Inheritance (max)
Multiple inheritance
2.7 Classic class, depth first
The new class after 3.0 is breadth first
Polymorphic
One interface, multiple implementations
Static methods
Only nominally attributed to the class to manage, but in fact there is no way to access the static method of the class or any attribute inside the instance
Class method
Only class variables can be accessed and instance variables cannot be accessed
Property method
Turn a method into a static property. You can change and delete methods by using the method name. Setter and method name. deleter.
Python Learning--static methods, class methods, property methods