Python Dunder Methods and Polymorphism

preview_player
Показать описание
Python dunder functions and operator overloading by implementing the Complex Number class.
Polymorphism means "different forms". So far we have created methods and dunder methods (operator overloading) as 2 ways of doing the same thing. For instance, we can create an add( ) method, or overload the __add__ operator.

We can apply the concept of polymorphism in our Complex Number class for function parameters. Here, we can add other Complex Number types or simple integers to our Complex Number. Unlike other programming languages, Python does not allow us to overload methods (define multiple functions with the same name). Instead since Python is dynamically typed, we can simply check the type of the value passed in to replicate this concept.

Python Playlist:

Subscribe for more coding tutorials 😄!
Рекомендации по теме