Implementation of Python class inheritance

Source: Internet
Author: User
Tags inheritance

Code:

#! /usr/bin/python # Filename:inherit.py # Author:yanggang class Schoolmember:def __init__ (self,n     

    Ame,age): self.name = name Self.age = age print ' init schoolmember: ', self.name def tell (self): print ' name:%s; age:%s '% (Self.name, Self.age) class Teacher (Schoolmember): def __init__ (self,name,age,salary): Sc hoolmember.__init__ (self,name,age) self.salary = salary print ' init Teacher: ', Self.name D EF Tell (self): Schoolmember.tell (self) print ' salary: ', Self.salary class Student (schoolmember): de F __init__ (Self,name,age,marks): schoolmember.__init__ (self,name,age) Self.marks = marks print ' in It Student: ', Self.name def tell (self): Schoolmember.tell (self) print ' marks: ', self.marks t = Tea Cher (' Yanggang ', 1000) s = Student (' Liming ', M,) members = [t,s] Print for member in Members:member.tell () 

Results:

[work@db-testing-com06-vm3.db01.baidu.com python]$ python inherit.py

Init Schoolmember:yanggang

Init Teacher:yanggang

Init schoolmember:liming

Init student:liming

Name:yanggang; Age:20

salary:1000

name:liming; Age:12

Marks:86

Related Article

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.