Exercise: Python

Questions for: Inheritance

How can you achieve method overloading in Python using variable-length arguments?
A:
By using the @overload decorator
B:
By explicitly specifying the data type of method parameters
C:
By defining a method with *args or **kwargs
D:
Method overloading is not possible in Python
Answer: C
Method overloading in Python can be achieved by defining a method with variable-length arguments using *args or **kwargs.
What is the purpose of the __iter__() method in Python classes?
A:
To define class attributes
B:
To create a new instance of the class
C:
To customize the iteration behavior of instances
D:
To access superclass attributes directly
Answer: C
The __iter__() method is used to customize the iteration behavior of instances of a class when used in a for loop or with the iter() function.
In Python, what is the purpose of the __bool__() method in a class?
A:
To define class attributes
B:
To create a new instance of the class
C:
To customize the boolean conversion behavior of instances
D:
To access superclass attributes directly
Answer: C
The __bool__() method is used to customize the boolean conversion behavior of instances of a class.
What is the purpose of the __format__() method in Python classes?
A:
To define class attributes
B:
To create a new instance of the class
C:
To customize the string formatting behavior of instances
D:
To access superclass attributes directly
Answer: C
The __format__() method is used to customize the string formatting behavior of instances of a class.
How can you achieve method overloading in Python using default values?
A:
By using the @overload decorator
B:
By explicitly specifying the data type of method parameters
C:
By defining multiple methods with different numbers of parameters and providing default values
D:
Method overloading is not possible in Python
Answer: C
Method overloading in Python can be achieved by defining multiple methods with different numbers of parameters and providing default values for some parameters.
Ad Slot (Above Pagination)
Quiz