Python Programming - Encapsulation - Discussion
Discussion Forum : Encapsulation - General Questions (Q.No. 77)
77.
Consider the following Python code:
class Product:
def __init__(self, name, __price):
self.name = name
self.__price = __price
def set_discount(self, discount):
if 0 < discount < 1:
self.__price *= (1 - discount)
What is the purpose of the set_discount() method?
Answer: Option
Explanation:
The set_discount() method allows setting a new discount for the product with validation, demonstrating encapsulation.
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