Python Programming - Encapsulation - Discussion

Discussion Forum : Encapsulation - General Questions (Q.No. 35)
35.
Consider the following Python code:
class Product:
    def __init__(self, name, price):
        self._name = name
        self._price = price

    @property
    def get_price(self):
        return self._price
What is the purpose of the @property decorator in this code?
To define a private variable
To create a class instance
To provide a getter method for a private variable
To access a global variable
Answer: Option
Explanation:
The @property decorator in this code is used to provide a getter method for the private variable _price.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.