Summary of the properties of a class (the properties of a class are defined in the method, the properties of the object are defined within the method)
Understand:
Class (Static) properties: (The human senses, understood as variables)
Class (Dynamic) method: ( Human clothing and shelter, understood as a function, at least with a parameter self, pointing to the class itself .
Object: The instantiation of a class before it can have properties and methods
1) The property of the class, which is also the public property; The private property of the class
2) Public properties of the object, private properties of the object
3) function local variable; global variable
4) built-in properties
#!/usr/bin/env python#encoding:utf-8var6 = "global variable Var6" Class myclass (object): var1 = class's public properties Var1 __var2 = private properties of class _var2 def fun1 (self): self.var3 = "method Public properties Var3" self.__var4 = " The private property of the method _var4 the local variable of the " var5 = " function Var5 " print var5 print var6 def fun2 (self): print self.var1 print Self.__var2 def fun3 (self): &nbSp; print self.var3 print self.__var4 mc = myclass () print mc.var1 # The public property of the external calling class print mc._myclass__var2 # the private property of the calling class, and the generic test uses print myclass.var1 # calling the class's public property through the class name #print myclass.__var2 # cannot call the class's private property through the class name #print myclass.var3 # cannot invoke the public and private properties of intrinsic functions through the class name #print myclass.__var4mc.fun1 () print mc.var3 The public property of the # external invocation method (which can be thought of as an intrinsic function with self), provided that the class is instantiated first and the method is executed #print mc.__var4 # External cannot invoke the private property of the method Mc = myclass () mc.fun2 () # internally calls the class's public, private property Mc = myclass () mc.fun1 ( MC.FUN3 () # intrinsic functions can invoke public, private properties of other intrinsics, provided that the class is instantiated first and the method is executed Mc = myclass () print myclass.__ dict__ # built-in property calls
Summary of properties and methods of the python-class