Python Object-oriented

Source: Internet
Author: User

#-*-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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.