Python Programming - Encapsulation - Discussion
Discussion Forum : Encapsulation - General Questions (Q.No. 86)
86.
In Python, what is the benefit of using a private variable with a double underscore prefix, such as __quantity?
class Inventory:
__quantity = 0
def update_quantity(self, quantity):
Inventory.__quantity += quantity
Answer: Option
Explanation:
Encapsulation with a double underscore prefix improves code maintainability by hiding the implementation details of the class attribute __quantity.
Discussion:
Be the first person to comment on this question !
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers