51. 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)
class test:
def __init__(self):
self.variable = 'Old'
self.Change(self.variable)
def Change(self, var):
var = 'New'
obj=test()
print(obj.variable)
52. 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
>>> class A:
def __init__(self,b):
self.b=b
def display(self):
print(self.b)
>>> obj=A("Hello")
>>> del obj
53. Let A and B be objects of class Foo. Which functions are called when print(A + B) is executed?
54. 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__))
class fruits:
def __init__(self, price):
self.price = price
obj=fruits(50)
obj.quantity=10
obj.bags=2
print(obj.quantity+len(obj.__dict__))
55. What is hasattr(obj,name) used for?
56. 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__)
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__)
57. What is the output of the following code:
class Parent:
x = 10
class Child(Parent):
pass
obj = Child()
print(obj.x)
class Parent:
x = 10
class Child(Parent):
pass
obj = Child()
print(obj.x)