August 2016
Beginner to intermediate
847 pages
17h 28m
English
We already created instances of the simple Rectangle class. We just needed to use the class name, specify the required arguments enclosed in parentheses, and assign the result to a variable.
The following lines declare a calculate_area method within the body of the Rectangle class:
def calculate_area(self):
return self.width * self.heightThe method doesn't require arguments to be called from an instance because it just declares the previously explained self parameter. The following lines create an instance of the Rectangle class named rectangle4 and then print the results of the call to the calculate_area method for this object:
rectangle4 = Rectangle(143, 187) print(rectangle4.calculate_area())
Now, imagine ...