Python Tutorial #48 - Operator Overloading in Python Programming

Published: 14 March 2023
on channel: Programming For Beginners
1,343
22

Python Tutorial #48 - Operator Overloading in Python Programming for Beginners
In this video by Programming for beginners we will see Operator Overloading in Python Programming for Beginners, in Python tutorial for beginners series.
Python programming language is very easy to learn for students and professionals.

In Python, we can change the way operators work for user-defined types.

For example, the + operator will perform arithmetic addition on two numbers, merge two lists, or concatenate two strings.
This feature in Python that allows the same operator to have different meaning according to the context is called operator overloading.

Python Special Functions
Class functions that begin with double underscore __ are called special functions in Python.
They are called "double underscore" functions because they have a double underscore prefix and suffix, such as __init__() or __add__().

__init__() - initialize the attributes of the object
__str__() - returns a string representation of the object
__len__() - returns the length of the object
__add__() - adds two objects
__call__() - call objects of the class like a normal function

Example code

Similarly, we can overload other operators as well:
Addition - p1 + p2 - p1.__add__(p2)
Subtraction - p1 - p2 - p1.__sub__(p2)
Multiplication - p1 * p2 - p1.__mul__(p2)
Power - p1 ** p2 - p1.__pow__(p2)
Division - p1 / p2 - p1.__truediv__(p2)
Floor Division - p1 // p2 - p1.__floordiv__(p2)

==========

Python Tutorial for Beginners Playlist:
   • Python Tutorial  

Java Tutorial for Beginners Playlist:
   • Java Tutorial  

All Java Programs Playlist:
   • Java Programs  

Python is a computer programming language often used to build websites and software, automate tasks, and conduct data analysis. Python is a general-purpose language, meaning it can be used to create a variety of different programs and isn't specialized for any specific problems.
It is very important for students and professionals to learn python programming language that will help you to achieve many tasks easily and to build softwares.

YouTube Gears:
Microphone: https://amzn.to/3iIk5K3
Mouse: https://amzn.to/35irmNF
Laptop: https://amzn.to/3iG0jyD

#PythonTutorial #Programming #PythonForBeginners #PythonTutorialForBeginners

============================
LIKE | SHARE | COMMENT | SUBSCRIBE

Thanks for watching :)


On this page of the site you can watch the video online Python Tutorial #48 - Operator Overloading in Python Programming with a duration of hours minute second in good quality, which was uploaded by the user Programming For Beginners 14 March 2023, share the link with friends and acquaintances, this video has already been watched 1,343 times on youtube and it was liked by 22 viewers. Enjoy your viewing!