[Path] Rollo of the Python object-oriented Python (d) Class Members

1.0 Object-oriented class members:

1.1 Fields

  1.1.1 ordinary field, which is stored in the object, do not call ()

  1.1.2 static field, the field general class which is written to a static field that indicates the default value. Can directly use class, direct call

1.2 Methods

  1.2.1 ordinary method, which is stored in the class, call with ()

 

The following normal class members:

class Foo:
     DEF  the __init__ (Self, name):
         # general field stored in the object inside 
        the self.name = name
     DEF Show (Self):
         # conventional method, which is stored in the class 
        Print ( ' the self.name ' ) 

obj = Foo ( ) 
obj.name   # field without () 
obj.show ()   # method call with ()

 

The following is a static field:

class Province:
     # static field belong to the class, stored in a memory only 
    Country = ' China ' 

    DEF  the __init__ (Self, name):
         # the normal field, the object belonging to 
        the self.name 

Print (Province.country)   # static fields, can be used class direct call

 

 

 

  

Guess you like

Origin www.cnblogs.com/rollost/p/10930828.html