Python_Questions_Answers
Python_Questions_Answers
---
**Choices**:
- **A**: Widget is defined as part of a public API, and we do not want any class
methods of Widget to access value.
- **B**: The widget is internal to your application and is the base class of a
diamond-shaped inheritance hierarchy, and we do not want derived class methods to
access value.
- **C**: The widget is internal to your application, and we do not want any class
methods of the Widget class to access value.
- **D**: The widget is internal to your application and is the base class of an
inheritance hierarchy, and we do not want derived class methods to access value.
- **E**: Widget is defined as part of a public API, and the clients of this API are
expected to subclass Widget in their own inheritance hierarchies. We do not want
methods of these subclasses to access value.
**Answer**: **D**
**Explanation**: Using `__value` invokes name mangling, which ensures that the
attribute is harder to access or override accidentally in derived classes. This is
particularly useful in inheritance hierarchies to protect the attribute.
---
**Choices**:
- **A**: Use multiple schedulers and make them run serially.
- **B**: Use a thread pool.
- **C**: None is correct.
- **D**: Use only jobQueue.queue that will queue relevant threads as and when
added.
**Answer**: **B**
**Explanation**: A thread pool allows you to control the number of threads,
ensuring efficient resource usage while preventing excessive thread creation.
---
**Choices**:
- **A**: If we do not implement the `__str__()` function, then a call to `str()` on
an object invokes `__repr__()`.
- **B**: An invocation of `__str__()` returns a user-friendly printable string that
can also be used by a debugger to reconstruct a representation of the original
object.
- **C**: A call to `repr()` invokes both `__repr__()` and `__str__()`, whereas a
call to `str()` invokes just `__str__()`.
- **D**: An invocation of `__repr__()` returns a developer-friendly printable
string that can be used by a debugger to reconstruct a representation of the
original object.
- **E**: If we do not implement `__repr__()`, then a call to `repr()` on an object
invokes `__str__()`.
---