Python Programming - Encapsulation - Discussion

Discussion Forum : Encapsulation - General Questions (Q.No. 62)
62.
How can encapsulation be achieved in Python to provide read-only access to a variable?
class Example:
    def __init__(self):
        self.__value = 42
Make __value a global variable
Create a getter method for __value
Use a single underscore prefix for __value
Make __value a public variable
Answer: Option
Explanation:
To provide read-only access to a variable, a getter method can be created to retrieve the value.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.