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