Python Programming - Encapsulation - Discussion

Discussion Forum : Encapsulation - General Questions (Q.No. 69)
69.
How can encapsulation be enhanced in the following Python class to provide write access to the 'price' variable?
class Product:
    def __init__(self, name, price):
        self.name = name
        self.__price = price
Use a double underscore prefix for 'price'
Create a setter method for 'price'
Make 'price' a global variable
Use a single underscore prefix for 'price'
Answer: Option
Explanation:
To provide write access to a private variable, a setter method can be created for 'price'.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.