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?
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:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers