Search⌘ K
AI Features

Python 2 vs. Python 3

Understand the improvements in class inheritance from Python 2 to Python 3 by examining the use of the super function and Method Resolution Order. Learn how Python 3 simplifies superclass initialization, making your code cleaner and more efficient.

Implementation in Python2

Let’s start by looking at a regular class definition. Then we’ll add super using Python 2 to see how it changes.

C++
class MyParentClass(object):
def __init__(self):
pass
class SubClass(MyParentClass):
def __init__(self):
MyParentClass.__init__(self)

This is a pretty standard set up for single inheritance. We have a base class and then the subclass. Another ...