+ 2

Operator overloading in Python 3

Can the + operator be used as an overloaded operator in the print statement in Python 3

2nd Mar 2021, 6:39 AM
Sanjay Kamath
Sanjay Kamath - avatar
3 Answers
+ 9
Sanjay Kamath , here is link to an explanation about operator overloading with various samples: https://www.geeksforgeeks.org/operator-overloading-in-JUMP_LINK__&&__python__&&__JUMP_LINK/
2nd Mar 2021, 8:16 AM
Lothar
Lothar - avatar
+ 4
Any example of the use case?
2nd Mar 2021, 6:52 AM
Ipang
+ 1
Python supports operator overloading. So you can use + operator in print function (I believe you meant print function). For example: >>print( "Hello " + "world!" ) Hello world! This works because python has operator overloading. Here two strings are concatenated using the string class's internal __add__( ) method which is how the operator overloading is implemented.
2nd Mar 2021, 7:26 AM
Abir Hasan
Abir Hasan - avatar