1 #!/usr/bin/env python2 #-*-coding:utf-8-*-3 ############################4 #File Name:class3.py5 #Author:frank6 #Email: [Email protected]7 #Created time:2017-09-04 14:55:168 ############################9 Ten classParent: Oneparentattr = 100 A def __init__(self): - Print "invoke construct of base class" - the defParentmethod (self): - Print "Invode Parentmethod" - - defsetAttr (Self, attr): +Parent.parentattr =attr - + defgetAttr (self): A Print "attr of base class:", Parent.parentattr at - defMyMethod (self): - Print 'calling the parent class method' - - classChild (Parent): - def __init__(self): in Print "invoke construct of sub class" - to defChildmethod (self): + Print "Invode Childmethod" - the defMyMethod (self): * Print 'Calling Subclass Methods' $ Panax Notoginsengc = Child ()#instantiating subclasses -C.childmethod ()#methods for calling subclasses theC.parentmethod ()#calling the parent class method +C.setattr (200)#call the parent class again-set the property value AC.getattr ()#call the Parent class again method-Get property value theC.mymethod ()
Python-class (3)