Question 1 of 25
Hints left: 3
Q1
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()
Q2
What will be the output of the following Python code? def add(c,k): c.test=c.test+1 k=k+1 class A: def __init__(self): self.test = 0 def main(): Count=A() k=0 for i in range(0,25): add(Count,k) print("Count.test=", Count.test) print("k =", k) main()
Q3
What is the difference between a class variable and an instance variable in Python?
Q4
How can you create a private attribute in a Python class?
Q5
How can you access a class variable in Python?
Q6
Which operator is overloaded by the __or__() function?
Q7
What does print(Test.__name__) display (assuming Test is the name of the class)?
Q8
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'))
Q9
What is the purpose of the @classmethod decorator in Python classes?
Q10
. . . . . . . . is used to create an object.
Q11
Which of the following Python code will print True? a = foo(2) b = foo(3) print(a < b)
Q12
What is getattr() used for?
Q13
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)
Q14
What is a constructor in Python classes?
Q15
Which function overloads the + operator?
Q16
What is the output of the following code: class Parent: def show(self): print('Parent method') class Child(Parent): pass obj = Child() obj.show()
Q17
What is setattr() used for?
Q18
Which function overloads the // operator?
Q19
What is the output of the following code: class MyClass: x = 5 obj = MyClass() print(obj.x)
Q20
The assignment of more than one function to a particular operator is . . . . . . . .
Q21
. . . . . . . . represents an entity in the real world with its identity and behaviour.
Q22
What are the methods which begin and end with two underscore characters called?
Q23
Which function overloads the == operator?
Q24
What is the purpose of the @staticmethod decorator in Python classes?
Q25
What is Instantiation in terms of OOP terminology?