Solution Review: Implement Rectangle Class Using Encapsulation
This review provides a detailed explanation for the 'Implement the Rectangle Class using the Concepts of Encapsulation' challenge.
We'll cover the following...
Solution
Python 3.5
class Rectangle:def __init__(self, length, width):self.__length = lengthself.__width = widthdef area(self):return (self.__length * self.__width)def perimeter(self):return (2 * (self.__length + self.__width))obj1 = Rectangle(4, 5)print("Area is", obj1.area())print("Perimeter is", obj1.perimeter())
Explanation
-
In lines 3 - ...
Ask