`

Python的集成

阅读更多

 

'''
Created on 2011-11-2
cn.py
@author: dudong0726
'''
from cn import Person

class Person(object):
    def __init__(self,name,sex,age):
        self.name = name
        self.sex = sex
        self.age = age
        
    def detail(self):
        return "my name is " + self.name + ".and "+ str(self.age) + " year's old."
 

class Teacher(Person):
    def __init__(self,name,sex,age,salary):
        Person.__init__(self, name, sex, age)
        self.salary = salary
    
    def detail(self):
        return "my name is " + self.name + ".and "+ str(self.age) + " year's old. I have " + str(self.salary) + " dollars per month."
    

class Student(Person):
    def __init__(self,name,sex,age,grade):
        Person.__init__(self, name,sex,age)  
        self.grade = grade
        
    def detail(self):
        return "my name is " + self.name + ".and "+ str(self.age) + " year's old. I have " + str(self.grade) + " in english test."
     
     
     
if __name__ == "__main__":
    p = Person("marry","woman",21)
    print(p.detail())
    p = Teacher("kevin","men",23,500)
    print(p.detail())
    p = Student("smith","men",25,90)
    print(p.detail())
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics