Directly paste their own written code to do the reference:
#encoding =utf-8__author__ = The definition of the ' Administrator ' # class # **KW dynamically adds the parameter class person to the object when creating an instance object of the Class (object): Def __init__ (self, NAME,AGE,**KW): # #每个类都有个init Method self.name = Name Self.age = age for K,v in Kw.iteritems (): SetAttr (Self,k,v) # # # Use SetAttr to assign dynamic properties to class object classes Teacher (person): #继承Person类 __score=0 # # defines private properties of a class that cannot be accessed by the outside world def __init__ (self,name,age,score): Self.__score = Score Super (teacher,self). __init__ (name,age) # #继承父类的 Initialize Method print "Teacher.__score =", Self.__score #---Methods also classify methods and instance methods #定义类方法 @classmethod declarations can be used directly with teacher.getscorefor Class () to invoke @classmethod def Getscoreforclass (CLS): Return Cls.__score #定义实例方法 directly with Teacher.getscoreforclass ( ) to call will error # P.getscoreforexample () def getscoreforexample (self): return self.__scorefrom types Import Methodtyp EIF __name__ = = "__main__": #te = Person ("TOM", 35,addr= "USA", sex= "M") # # Class Instance Object TE "can directly change the value of an object instance, such as: Te.name = "BOB" can also be directly to the object instance to add the genusSex, such as: Te.lover = "SUM" does not add properties to the class, when you are in this common instance of a class is not the property just added "print" befor: ", Teacher.getscoreforclass () p = Teacher ("TOM", 33,100) print "After:", P.getscoreforexample () print "After:", Teacher.getscoreforclass ()