So when I want to know the type of this number two it's going to show this kind of output.
And this means that two is an object of the class in.
Now when I once again want to know that type of let's say 2.0 it's an object of class float when I
want to do the same operation with the string.
This string is an object of class String.
So everything is an object in Python.
Now have you ever wondered that when you do two plus two it's going to give us the addition of two numbers.
and when I add the two strings.
Let's say two and then I'm going to use the same operator which is plus operator.
with the other string it's going to give me the concatenation of these two string values.
So the same operator Plus is working differently with different type of objects the same.
You might have observed with the multiplication operator which is this Astrisk.
So when I use this Astrisk or multiplication operator with a string and let's say I write three here
it's going to print this given string three times but the same operator and I will use with that two
numbers.
It's going to give me that different behavior which is the multiplication of these two numbers.
So the same operator Astrisk is functioning differently with different kind of data or in other words
we can say that this Astrisk operator or this plus OPERATOR Are overloaded for a different kind
of objects.
So when ever this plus operator is used with two numbers it's going to give us the sum of these two numbers.
And whenever this operator is used with the string it's going to give us the concatenation of
these two strings.
So both these operators are overloaded for handling different kind of data.
So this is the overloading of the build in operators.
Now we might also think that if this is possible can we overload the operators by our custom classes.
So let me create a class and I'm going to name it as the number class which is going to take one argument.
So let me define a constructor here.
So I underscore underscore init underscore underscore and this is going to take one argument which
is the number.
And I'm going to just write self dot Numb is equal to numb.
So this is a simple class which we have created.
And now I'm going to create two instance of the same class so number and I'm going to give the number
one let's say here and then I'm going to create a second object of this class and this time I'm going
to give the number two here.
So is it possible that we can use let's say n1 plus n2.
So let's try this.
And it's going to give us this error.
it says unsupported operant type for plus number and number.
So because Python doesn't know how to use this plus operator with your class objects it's going to give
us this.
error It is unsupported operand type and whatever is the operator you are using.
So it turns out that we can overload these kind of operators in Python by implementing some inbuilt
methods in our class.
So we already know that whenever we want to implement a constructor in python we use this intit method.
So I'm going to create a very simple class and I'm going to name it as a.
And that this will be a blank Class.
So this is a very simple class in Python.
**************************************************************************
please like and follow us in Facebook and Instagram.
facebook: / technologytv
Instagram: / heikhamsingh
Twitter: / hanandkumarsing