Tutorial 4: OOPs in Python — Polymorphism

Gaurav Patil
3 min readJan 13, 2022
Photo by Hitesh Choudhary on Unsplash

Missed previous lecture ?? — Click here

In this tutorial we will cover following topics :

Polymorphism

Polymorphism in Python’s built-in functions

Polymorphism in Python’s user-defined class functions

help() function for built-in class and user-defined class

Polymorphism

Polymorphism = Poly + morphs

Poly means many and morph means form.

Here ‘Polymorphism’ = same function(method) name with different functionalities for different classes

Polymorphism in Python’s built-in functions

Polymorphism in Python’s user-defined class functions :

Let’s understand polymorphism using examples :

Example 1

Example 2

help() function for built-in class and user-defined class :

Let’s appreciate the beauty of Python language .

help() function in python gives general information about any python object if passed inside parentheses. As you can see below it works for built-in class ‘list’.

Let’s see if help() function works for user-defined class object.

Yes it works !!!.

You can see above when help() function is called for ‘num_square’ object , __init__ and area() methods are also mentioned including the number of attributes every method takes.

Congratulations !!

You have completed fourth tutorial. Take a deep breathe and move to the next tutorial.

--

--

Gaurav Patil

Machine Learning Engineer drawing insights from mathematics.