Python Programming - Encapsulation - Discussion

Discussion Forum : Encapsulation - General Questions (Q.No. 98)
98.
In Python, what is the benefit of using a private variable with a double underscore prefix, such as __stock_quantity?
class Inventory:
    __stock_quantity = 0

    def update_stock(self, quantity):
        Inventory.__stock_quantity += quantity
It improves code maintainability by hiding implementation details
It allows unrestricted access to __stock_quantity
It exposes all internal details of __stock_quantity
It creates a global variable
Answer: Option
Explanation:
Encapsulation with a double underscore prefix improves code maintainability by hiding the implementation details of the class attribute __stock_quantity.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.