QuesAns Print Page – CSKC
Sign In

Search

siteicon
Q&A CBSE12D-2015-B02D #6527

Question:

What is operator overloading with methods? Illustrate with the help of an example using a python code.

Answer:

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