Python Programming - Encapsulation - Discussion
Discussion Forum : Encapsulation - General Questions (Q.No. 76)
76.
How can encapsulation be enforced in Python to make a variable 'username' accessible only within its own class?
class User:
def __init__(self, username, __password):
self.username = username
self.__password = __password
Answer: Option
Explanation:
Adding a double underscore prefix before 'username' makes it a private variable, enforcing encapsulation within the class.
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