Q: Which function is called when the following Python code is executed? f = foo() format(f)
Solution: Both str(f) and format(f) call f.__str__().
Q: Which of the following Python code will print True? a = foo(2) b = foo(3) print(a < b)
Solution: __lt__ overloads the < operator>.
Q: Which function overloads the + operator?
Solution: Refer documentation.
Q: Which operator is overloaded by __invert__()?
Solution: __invert__() overloads ~.
Q: Which function overloads the == operator?
Solution: The other two do not exist.
Q: Which operator is overloaded by __lg__()?
Solution: __lg__() is invalid.
Q: Which function overloads the >> operator?
Solution: __rshift__() overloads the >> operator.
Q: Let A and B be objects of class Foo. Which functions are called when print(A + B) is executed?
Solution: 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.
Q: Which operator is overloaded by the __or__() function?
Solution: The function __or__() overloads the bitwise OR operator |.
Q: Which function overloads the // operator?
Solution: __floordiv__() is for //.
You Have Score    | /10 |