Category: 4. Single inheritance
-
Python Abstract Classes
Summary: in this tutorial, you’ll learn about Python Abstract classes and how to use it to create a blueprint for other classes. Introduction to Python Abstract Classes In object-oriented programming, an abstract class is a class that cannot be instantiated. However, you can create classes that inherit from an abstract class. Typically, you use an abstract class…
-
Python __slots__
Summary: in this tutorial, you will learn about the Python __slots__ and how how to use it to make your class more efficient. Introduction to the Python __slots__ The following defines a Point2D class that has two attributes including x and y coordinates: Each instance of the Point2D class has its own __dict__ attribute that stores the instance attributes. For example: By default, Python uses the dictionaries to manage the…
-
Python super
Summary: in this tutorial, you will learn how to use the Python super() to delegate to the parent class when overriding methods. Introduction to the Python super First, define an Employee class: The Employee class has three instance variables name, base_pay, and bonus. It also has the get_pay() method that returns the total of base_pay and bonus. Second, define the SalesEmployee class that inherits from the Employee class: The SalesEmployee class has four…
-
Python Overriding Method
Summary: in this tutorial, you’ll learn how to use Python overriding method to allow a child class to provide a specific implementation of a method that is provided by one of its parent classes. Introduction to Python overridding method The overriding method allows a child class to provide a specific implementation of a method that…
-
Python Inheritance
Summary: in this tutorial, you’ll learn about Python inheritance and how to use the inheritance to reuse code from an existing class. Introduction to the Python inheritance Inheritance allows a class to reuse the logic of an existing class. Suppose you have the following Person class: The Person class has the name attribute and the greet() method. Now, you want to define the Employee that is similar…