Solved Problem Solved Problem#PYTHON#6357
Problem Statement - B02D-2015
What is operator overloading with methods? Illustrate with the help of an example using a python code.
Solution
Operator overloading is an ability to use an operator in more than one form.
Examples:
In the following example operator + is used for finding the sum of two integers:
a = 7 b = 5 print(a+b) # gives the output: 12
Whereas in the next example, shown below the same + operator is used to add two strings:
a = 'Indian ' b = 'Government' print(a+b) # gives the output: Indian Government