This Quiz contains totally 10 Questions each carry 1 point for you.
1. If you have a class that is derived from two different classes, it's called
Multilevel Inheritance
Multiple Inheritance
Hierarchical Inheritance
Python Inheritance
Correct!
Wrong!
2. What is the output of the following code?
class Point:
def __init__(self, x = 0, y = 0):
self.x = x+1
self.y = y+1
p1 = Point()
print(p1.x, p1.y)
0 0
1 1
None
X Y
Correct!
Wrong!
3. 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()
Runs normally, doesn’t display anything
Displays 0, which is the automatic default value
Error as one argument is required while creating the object
Error as display function requires additional argument
Correct!
Wrong!
4. What will be the output of the following Python code?
class fruits:
def __init__(self, price):
self.price = price
obj=fruits(50)
obj.quantity=10
obj.bags=2
print(obj.quantity+len(obj.__dict__))
12
13
52
60
Correct!
Wrong!
5. What is setattr() used for?
To access the attribute of the object
To set an attribute
To check if an attribute exists or not
To delete an attribute
Correct!
Wrong!
6. What will be the output of the following Python code?
class demo():
def __repr__(self):
return '__repr__ built-in function called'
def __str__(self):
return '__str__ built-in function called'
s=demo()
print(s)
__str__ called
__repr__ called
Error
Nothing is printed
Correct!
Wrong!
7. What does print(Test.__name__) display considering Test is the name of the class?
( )
Exception is thrown
Test
__main__
Correct!
Wrong!
8. __del__ method is used to destroy instances of a class.
True
False
Correct!
Wrong!
9. What does the __init__() the function do in Python?
Initializes the class for use.
This function is called when a new object is instantiated.
When called initializes all the data attributes to zero.
None of the above.
Correct!
Wrong!
10. Which of the following is not a class method?
Non-static
Static
Bounded
Unbounded
Correct!
Wrong!
Share the quiz to show your results !
Subscribe to see your results
Ignore & go to results
Python-Classes-Quiz
You got %%score%% of %%total%% right
%%description%%
%%description%%
Loading...