The assignment of more than one function to a particular operator is . . . . . . . .
A. Operator over-assignment
B. Operator overriding
C. Operator overloading
D. Operator instance
Select an option to see the answer and solution.
What is the difference between a class variable and an instance variable in Python?
A. A class variable is shared among all instances of a class, while an instance variable is unique to each instance
B. They are the same
C. An instance variable is shared among all instances
D. A class variable is unique to each instance
Select an option to see the answer and solution.
How can you access a class variable in Python?
A. Using the class name and dot notation
B. Using the self keyword
C. Using the cls keyword
D. Using the object keyword
Select an option to see the answer and solution.
. . . . . . . . represents an entity in the real world with its identity and behaviour.
A. A method
B. An object
C. A class
D. An operator
Select an option to see the answer and solution.
. . . . . . . . is used to create an object.
A. class
B. constructor
C. User-defined functions
D. In-built functions
Select an option to see the answer and solution.
What are the methods which begin and end with two underscore characters called?
A. Special methods
B. In-built methods
C. User-defined methods
D. Additional methods
Select an option to see the answer and solution.
What is setattr() used for?
A. To access the attribute of the object
B. To set an attribute
C. To check if an attribute exists or not
D. To delete an attribute
Select an option to see the answer and solution.
What is getattr() used for?
A. To access the attribute of the object
B. To delete an attribute
C. To check if an attribute exists or not
D. To set an attribute
Select an option to see the answer and solution.
What is the output of the following code:class MyClass: x = 5 obj = MyClass() print(obj.x)
A. 5
B. An error will occur
C. obj
D. MyClass
Select an option to see the answer and solution.
What is the output of the following code:class Parent: def show(self): print('Parent method') class Child(Parent): pass obj = Child() obj.show()
A. Parent method
B. An error will occur
C. Child method
D. obj
Select an option to see the answer and solution.
What is the purpose of the @staticmethod decorator in Python classes?
A. It defines a method that belongs to the class rather than an instance
B. It defines a static attribute
C. It defines a global function
D. It defines a constructor
Select an option to see the answer and solution.
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)A. It isn't as the object declaration isn't right
B. It isn't as there isn't any __init__ method for initializing class members
C. Yes, this method of calling is called unbounded method call
D. Yes, this method of calling is called bounded method call
Select an option to see the answer and solution.
Which function overloads the == operator?
A. __eq__()
B. __equ__()
C. __isequal__()
D. none of the mentioned
Select an option to see the answer and solution.
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'))A. Error as age isn't defined
B. True
C. False
D. 7
Select an option to see the answer and solution.
What does print(Test.__name__) display (assuming Test is the name of the class)?
A. ()
B. Exception is thrown
C. Test
D. __main__
Select an option to see the answer and solution.
What is a constructor in Python classes?
A. A special method that is automatically called when an object is created
B. A built-in function
C. A method that creates an object
D. A method that destroys an object
Select an option to see the answer and solution.
Which of the following Python code will print True?
a = foo(2)
b = foo(3)
print(a < b)Options are not available for this question.
Select an option to see the answer and solution.
Which function overloads the + operator?
A. __add__()
B. __plus__()
C. __sum__()
D. none of the mentioned
Select an option to see the answer and solution.
What is the purpose of the @classmethod decorator in Python classes?
A. It defines a method that belongs to the class and not the instance
B. It defines a static method
C. It defines a constructor
D. It defines a destructor
Select an option to see the answer and solution.
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()
A. Child constructor
B. Parent constructor
C. An error will occur
D. Child Parent
Select an option to see the answer and solution.