Python Programming - Encapsulation - Discussion

Discussion Forum : Encapsulation - General Questions (Q.No. 45)
45.
Consider the following Python code:
class Customer:
    def __init__(self, name, email):
        self._name = name
        self._email = email

    def display_info(self):
        return f"Name: {self._name}, Email: {self._email}"
What concept of encapsulation is demonstrated in this code?
Public access specifier
Private access specifier
Protected access specifier
Global variable
Answer: Option
Explanation:
The single underscore prefix (_) in the variables _name and _email indicates that they are private variables, 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.