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
- Operator Overloading in Python
- Concatenate strings from several rows using Pandas groupby
- Python | Ways to concatenate two lists
- Python | Concatenate two lists element-wise
- Python program to concatenate two Integer values into one
- Python | Merge, Join and Concatenate DataFrames using Panda
- Concatenate images using OpenCV in Python
- Concatenate two columns of Pandas dataframe
- How to Concatenate two 2-dimensional NumPy Arrays?
- Benefits of Double Division Operator over Single Division Operator in Python
- Python | Pandas Series.str.cat() to concatenate string
- Python | Ways to concatenate boolean to string
- Python | Concatenate dictionary value lists
- Python | Ways to concatenate tuples
- Python | Numpy np.ma.concatenate() method
- Python | How to Concatenate tuples to nested tuples
- Python | Concatenate N consecutive elements in String list
- Python - Concatenate Kth element in Tuple List
- Python - Concatenate consecutive elements in Tuple
- Python | Concatenate All Records
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.