Home > Python > Quizzes > Python Programming Basics Practice Test: Python Operator Overloading, Classes And Objects
Python Programming Basics Practice Test: Python Operator Overloading, Classes And Objects
Fast practice, instant feedback. Timer auto-submits when time’s up.
Avg score: 20% Most missed: “Which of the following is not a class method?”
Operator overloading is a feature in Python that allows you to define custom behavior for operators when used with your own objects. This is done by implementing special methods with double underscores before and after the operator name.  For example, to define custom addition behavior for your Point class, you would implement the __add__() method. Operator overloading can be used to implement a wide variety of custom behaviors for your own objects. For example, you could overload the + operator to concatenate two strings, or the * operator to multiply two matrices. However, it is... Show more
Python Programming Basics Practice Test: Python Operator Overloading, Classes And Objects
Time left 00:00
25 Questions

1. What does print(Test.__name__) display (assuming Test is the name of the class)?
2. __del__ method is used to destroy instances of a class.
3. _____ is used to create an object.
4. Which function overloads the // operator?
5. What are the methods which begin and end with two underscore characters called?
6. Which function overloads the == operator?
7. Which of the following is not a class method?
8. What is setattr() used for?
9. What is hasattr(obj,name) used for?
10. _____ is used to create an object.
11. What will be the output of the following Python code?
class test:
def __init__(self,a="Hello World"):
self.a=a
 
def display(self):
print(self.a)
obj=test()
obj.display()
12. Which function overloads the == operator?
13. Special methods need to be explicitly called during object creation.
14. What is delattr(obj,name) used for?
15. What will be the output of the following Python code?
class change:
def __init__(self, x, y, z):
self.a = x + y + z
 
x = change(1,2,3)
y = getattr(x, 'a')
setattr(x, 'a', y+1)
print(x.a)
16. What are the methods which begin and end with two underscore characters called?
17. What will be the output of the following Python code?
class Demo:
def __init__(self):
pass
 
def test(self):
print(__name__)
 
obj = Demo()
obj.test()
18. What will be the output of the following Python code?
class change:
def __init__(self, x, y, z):
self.a = x + y + z
 
x = change(1,2,3)
y = getattr(x, 'a')
setattr(x, 'a', y+1)
print(x.a)
19. Which function is called when the following Python code is executed?
f = foo()
format(f)
20. Which of the following is not a class method?
21. Which operator is overloaded by __lg__()?
22. Which operator is overloaded by __invert__()?
23. What is setattr() used for?
24. What will be the output of the following Python code?
class test:
def __init__(self,a):
self.a=a
 
def display(self):
print(self.a)
obj=test()
obj.display()
25. What is Instantiation in terms of OOP terminology?