0
What is operator-overloading in python?
3 ответов
+ 10
For integers:
2 + 4 = 6
For strings:
"2" + "4" = "24"
For tuples:
(2,) + (4,) = (2, 4)
and so on.
Each time you use the same operator - "+" - and it knows what to do with every data type. This is because it is implemented differently for each class. And that is what operator overloading is about.
+ 6
It is a property of the operator to act differently depending on the class of its arguments.
You can use the __add__ operator (expressed by the 'plus' sign) with integers, floats, strings, lists, tuples and other data types.
Each time it will act differently - performing mathematical operation or concatenation or joining/merging - its behavior is class-dependent.
0
please give me examples