In a Python codebase, you see that a child class is trying to modify an attribute with two leading underscores from a parent class but encounters an error. What's the likely cause?
- Python does not allow modifying attributes from child classes.
- The attribute is marked as a protected attribute and can only be accessed within the parent class.
- The attribute with double underscores is treated as a name mangling name, and it's not directly accessible from child classes.
- The child class does not have proper inheritance from the parent class.
In Python, an attribute with double underscores (e.g., __attribute) is treated as a name-mangling name. It's not directly accessible from child classes to prevent accidental overwriting.
Loading...
Related Quiz
- The ____ built-in function is used to convert a variable to an integer data type, if possible.
- When using decorators, what is the significance of the functools.wraps function?
- Which Python module would you use for measuring the performance of small code snippets?
- In Python, a class member prefixed with two underscores, such as __memberName, is conventionally considered as _______.
- The ____ sort algorithm repeatedly divides the list into two halves until each sub-list contains a single element.