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)
Output:
Hello Python -> + operator joins two strings instead of performing addition.
Example 2:
print(5 + 3)
Output:
8 -> + operator performs arithmetic addition.
Top comments (0)