Notice how the methods are defined using the keyword – def. Notice also, that the ‘print_details’ method takes ‘self’ as a parameter and prints the student name, branch and year.
Inheritance is a core object-oriented concept in the Python programming language. It allows one to reuse or extend the functionality or features of one or more classes that are “inherited” in a new class. The concept of inheritance in Python is similar to other high-level programming languages such as C#, Java etc.
Let’s define a person class with a method to get the person’s details.
Now, let us revise the “Student” class to inherit from “Person” so it can get all the features of the person.
Once we inherit from the person, the student gets the behavior “get_details”. Notice, however, that the revised Student class overrides the behavior of “get_details” and adds its own functionality.
Note – It’s up to the implementor to decide whether to override a method or not.
This article provides an overview of the Python programming language, its core features, and simple, accessible syntax. Hopefully, this brief introduction provides a glimpse into Python’s simplicity and encourages you to explore it as a potential addition to your programmer's toolbox.
Aezion Inc. Solution Architects, Engineers, and Developers can assist you in exploring Python-based Software Solutions for your Data Science and Machine Learning applications. Contact us to learn more.