What Are Differences Between type() and isinstance()?

The main difference between type() and isinstance() is that type(object) returns the type of an object and isinstance(object, class) returns True if the object argument is an instance of the class argument or in a direct or indirect subclass relationship. To strengthen your understanding, let’s quickly recap the syntactical definitions of both functions: type(object) – … Read more

Python Method Resolution Order (MRO)

Today we’re going to look at the Python Method Resolution Order or MRO for short. If you’ve been following the tutorials on Python classes and inheritance, and you’ve been practicing in code, you’ll understand that once the hierarchy of classes moves into multiple inheritances, you may return strange results or end up with incomprehensible errors. … Read more

Five Types of Inheritance in Python

In a previous article, we introduced the topic of object-oriented programming, or OOP for short. Then, we discussed classes and the topic of inheritance. This article will do a quick recap of inheritance, what it is, and why you’d use it. Then we’ll introduce the different types of inheritance you might encounter in your programming … Read more

An Introduction To Python Classes – Inheritance, Encapsulation, and Polymorphism

This article continues from Introduction to Classes – Part One, where we explained what classes are, their components, and why we use them. We also looked at some unique characteristics of classes that assist us in creating cleaner code. If you haven’t read Part One and are new to classes, I suggest reading that introduction … Read more

Introduction to Python Classes

This article introduces classes in Python, explaining what they are, their components, and why we use them. We’ll also look at some unique characteristics of classes to assist us in creating cleaner code. When I first began coding, the subject of classes in Python was a complete mystery to me. The explanations and jargon employed … Read more

Method Overriding vs Overloading in Python [+Video]

Method overriding vs overloading in Python—what’s the difference? If you’re short on time—here it is: Method overloading: creating a method that can be called with different arguments such as m() and m(1, 2, 3). Method overriding: overwriting the functionality of a method defined in a parent class. In method overloading, methods in a given class … Read more

How to Get a Function Name as a String in Python?

Problem Formulation Given a function object assigned to a name. How to get the name of the function as a string? For example, consider the following function your_function. How to get the name “your_function” from this? Your desired value of the result stored in string_name is the string “your_function”. Method 1: Use the __name__ Attribute … Read more

Inheritance in Python

You have the eyes of your mother. One could say, you “inherited” the eyes of your mother. As you may have guessed, this article is about inheritance in Python. Inheritance is one of the most important features of object orientation. It’s a simple and intuitive concept but even advanced coders circumvent using inheritance because they … Read more