Vidyalelo
Python · all questions

Classes and Objects in Python
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

67

Questions

4/4

Page

Pick an option on a question to see the right answer and solution.

How can you create a static variable in a Python class?

Select an option to see the answer and solution.

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)

Select an option to see the answer and solution.

What is the purpose of the @property decorator in Python classes?

Select an option to see the answer and solution.

What is the output of the following code:
class MyClass:
count = 0
def init(self):
MyClass.count += 1
obj1 = MyClass()
obj2 = MyClass()
print(obj1.count)

Select an option to see the answer and solution.

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)

Select an option to see the answer and solution.

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()

Select an option to see the answer and solution.

What is delattr(obj,name) used for?

Select an option to see the answer and solution.