32. Is the following Python code valid?
class B(object):
def first(self):
print("First method called")
def second():
print("Second method called")
ob = B()
B.first(ob)
class B(object):
def first(self):
print("First method called")
def second():
print("Second method called")
ob = B()
B.first(ob)
33. Which function overloads the == operator?
34. What will be the output of the following Python code?
class stud:
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)
stud1 = stud(34, 'S')
stud1.age=7
print(hasattr(stud1, 'age'))
class stud:
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)
stud1 = stud(34, 'S')
stud1.age=7
print(hasattr(stud1, 'age'))
35. What does print(Test.__name__) display (assuming Test is the name of the class)?
36. What is a constructor in Python classes?
37. Which of the following Python code will print True?
a = foo(2)
b = foo(3)
print(a < b)
a = foo(2)
b = foo(3)
print(a < b)
38. Which function overloads the + operator?
39. What is the purpose of the @classmethod decorator in Python classes?
40. What is the output of the following code:
class Parent:
def init(self):
print('Parent constructor')
class Child(Parent):
def init(self):
print('Child constructor')
obj = Child()
class Parent:
def init(self):
print('Parent constructor')
class Child(Parent):
def init(self):
print('Child constructor')
obj = Child()