#-*-Coding:utf-8-*-
Class Person:
' A doc string for you class '
Population = 0
def __init__ (self,name):
"' Initial the person ' s data '
Self.name = Name
print ' Initial the ', Self.name
Person.population + = 1
def __del__ (self):
"I Am Dying"
print '%s says bye '% self.name
Person.population-= 1
If person.population = = 0:
print ' I am the last one. '
Else
print ' still%d left '% person.population
def sayhi (self):
"A doc for function"
print ' Hello,how is you? '
print ' My name is ', Self.name
def howmany (self):
if person.population = = 1:
print ' Only one persion '
Else
print ' We have%d persion '% person.population
p = person (' John ')
P.sayhi ()
Class Schoolmember:
"' represents any school member '
def __init__ (self,name,age):
Self.name = Name
Self.age = Age
print ' Initialized school member:%s '% self.name
def tell (self):
"Tell my Detials"
print ' Name: '%s ' Age: '%d ' '% (self.name,self.age)
Class Teacher (Schoolmember):
"' Represents a teacher"
def __init__ (self,name,age,salary):
schoolmember.__init__ (Self,name,age)
Self.salary = Salary
print ' initialized teacher:%s '% self.name
def tell (self):
Schoolmember.tell (self)
print ' Salary: '%d ' '% self.salary
Class Student (Schoolmember):
"' Represents a student"
def __init__ (Self,name,age,marks):
schoolmember.__init__ (Self,name,age)
Self.marks = Marks
print ' Initialize student:%s '% self.name
def tell (self):
Schoolmember.tell (self)
print ' Marks: '%d ' '% self.marks
t = Teacher (' Owenxie ', 25,30050)
s = Student (' Owenxie ', 25,74)
For member in T,s:
Member.tell ()
Python Object-oriented