Question 1 of 25
Hints left: 3
Q1
What is the purpose of the @property decorator in Python classes?
Q2
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()
Q3
Which function overloads the >> operator?
Q4
Let A and B be objects of class Foo. Which functions are called when print(A + B) is executed?
Q5
Which of the following is not a class method?
Q6
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)
Q7
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)
Q8
What is the output of the following code: class Parent: x = 10 class Child(Parent): pass obj = Child() print(obj.x)
Q9
What is hasattr(obj,name) used for?
Q10
__del__ method is used to destroy instances of a class.
Q11
What will be the output of the following Python code? class test: def __init__(self): self.variable = 'Old' self.Change(self.variable) def Change(self, var): var = 'New' obj=test() print(obj.variable)
Q12
What is the purpose of the super() function in Python classes?
Q13
Is the following Python code correct? >>> class A: def __init__(self,b): self.b=b def display(self): print(self.b) >>> obj=A("Hello") >>> del obj
Q14
How can you check if an object belongs to a specific class in Python?
Q15
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()
Q16
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)
Q17
Special methods need to be explicitly called during object creation.
Q18
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__))
Q19
What will be the output of the following Python code? class stud: ‘Base class for all students’ def __init__(self, roll_no, grade): self.roll_no = roll_no self.grade = grade def display (self): print("Roll no : ", self.roll_no, ", Grade: ", self.grade) print(student.__doc__)
Q20
What is delattr(obj,name) used for?
Q21
How can you create a static variable in a Python class?
Q22
What is the main goal of object-oriented programming (OOP)?
Q23
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)
Q24
Which of the following Python code creates an empty class?
Q25
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()