1.

Let A and B be objects of class Foo. Which functions are called when print(A + B) is executed?(a) __add__(), __str__()(b) __str__(), __add__()(c) __sum__(), __str__()(d) __str__(), __sum__()I got this question in an interview.My question is from Operator Overloading in portion Classes and Objects, Inheritance, Polymorphism, Encapsulation and Exception Handling of Python

Answer»

Right OPTION is (a) __add__(), __str__()

For EXPLANATION: The FUNCTION __add__() is called first since it is within the bracket. The function __str__() is then called on the object that we received after ADDING A and B.



Discussion

No Comment Found

Related InterviewSolutions