Python Subclass Inherits Parent class

Source: Internet
Author: User

Written programs know the class, is the object-oriented meaning, the level of programming is broadly divided into several levels, basic syntax, functions, object-oriented, data structure, architecture, the higher the higher the level.

When creating a class, we usually wrap a function with a dependency as a class, and a class can be nested, called a parent class and a subclass, especially in Python, where all objects can be treated as a variable, and a nested example of a class is given below.

Class Metric (object):

def __init__ (self):

Self.var = "Hadoop"

def print_metric (self):

Print "I AM General metric:%s"% Self.var


Class Jmx_metric (Metric):

def __init__ (self):

Metric.__init__ (self)

def print_jmx_metric (self):

Print Metric.print_metric ()


Metric = Jmx_metric ()

Metric.print_jmx_metric ()


Executor Result:

I AM General Metric:hadoop


The parent class is written inside the subclass, inheriting the attribute and methods of the parent class, but the __init__ method of the parent class is executed before the variable is called.



This article from "Linux operation and Maintenance" blog, declined reprint!

Python Subclass Inherits Parent class

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.