Python Programming - Encapsulation - Discussion

Discussion Forum : Encapsulation - General Questions (Q.No. 80)
80.
How can encapsulation be enforced in Python to make a variable 'email' accessible only within its own class?
class User:
    def __init__(self, email, __password):
        self.email = email
        self.__password = __password
Use a getter method for 'email'
Add a single underscore prefix before 'email'
Make 'email' a global variable
Add a double underscore prefix before 'email'
Answer: Option
Explanation:
Adding a double underscore prefix before 'email' makes it a private variable, enforcing encapsulation within the class.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.