Learn Before
Code

Defining a Subclass in Python

To define a subclass in Python, you can use the following syntax:

class ParentClass(): def __init__(self): self.some_attribute = 5 def some_function(self, x): return self.some_attribute + x class SubClass(ParentClass): some_new_attribute = self.some_attribute + 7 def some_new_function(self): return self.some_function(some_new_attribute)

An instance of the class SubClass will inherit the methods and attributes of ParentClass.

0

0

Updated 2021-02-17

Tags

Python Programming Language

Data Science