Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Few questions on object-oriented programming in python 3 1. Assuming that the __

ID: 3711407 • Letter: F

Question

Few questions on object-oriented programming in python 3

1. Assuming that the __add__ operator is implemented for two objects, x and y, then x+y is equivalent to:

A. add(x,y)

B. y.__add__(x)

C. x.__add__(y)

D. __add__(x,y)

2. A class can define the behavior for the < operator.

A. True

B. False

3. The method name for non-integer division is:

A. /

B. __div__

C. //

D. __truediv__

4. By default calling the str function on a custom object will:

A. print the memory address of that object

B. print the name of the object

C. print a description of that object

D. print the name of the class

5. Typically, a definition of the __add__ method should:

A. Change the left operand

B. Return a new instance of the left operand type

C. Change the right operand

D. Return a new instance of the right operand type

6. By default, if you use the + operator on two user-defined objects:

A. The two objects will be added together

B. the two objects will be combined

C. an error will occur.

D. a new object will be created

Explanation / Answer

1) C. x.__add__(y) 2) A. True 3) D. __truediv__ 4) A. print the memory address of that object 5) B. Return a new instance of the left operand type 6) C. an error will occur.