DEV Community

Punitha
Punitha

Posted on

Operator Overloading

What is Operator Overloading?

  • Operator overloading allows operators such as +, -, *, and == to have different meanings depending on the objects they are used with.

Example 1:

a = "Hello"
b = "Python"

print(a + b)
Enter fullscreen mode Exit fullscreen mode

Output:

Hello Python    -> + operator joins two strings instead of performing addition.
Enter fullscreen mode Exit fullscreen mode

Example 2:

print(5 + 3)
Enter fullscreen mode Exit fullscreen mode

Output:

8               -> + operator performs arithmetic addition.
Enter fullscreen mode Exit fullscreen mode

Top comments (0)