Python Programming - Encapsulation - Discussion

Discussion Forum : Encapsulation - General Questions (Q.No. 60)
60.
In Python, what is the purpose of using a double underscore prefix before a variable, such as __price?
class Product:
    def __init__(self, name, __price):
        self.name = name
        self.__price = __price
To indicate a public variable
To define a private variable
To create a class method
To allow unrestricted access to the variable
Answer: Option
Explanation:
The double underscore prefix (__price) indicates that it is a private variable, demonstrating encapsulation by hiding the implementation details.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.