Concatenate two strings using Operator Overloading in Python
Operator Overloading refers to using the same operator to perform different tasks by passing different types of data as arguments. To understand how ‘+’ operator works in two different ways in python let us take the following example
The sum of these two numbers is 5
In this example we used ‘+’ operator to add numbers, now let us take one more example to understand how ‘+’ operator is used to concatenate strings.
After Concatenation the string becomes abcdef
For a better understanding of operator overloading, here is an example where a common method is used for both purposes.
sum is 32 Concatenated string is 239
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course