Python Programming - Objects - Discussion
Discussion Forum : Objects - General Questions (Q.No. 18)
18.
Consider the following Python code:
class Square:
def __init__(self, side_length):
self.side_length = side_length
def calculate_area(self):
return self.side_length ** 2
If you create an instance of the `Square` class called small_square
with a side length of 3, what will be the result of calling small_square.calculate_area()
?
Answer: Option
Explanation:
The
calculate_area
method calculates the area of the square using the formula side_length ** 2. For the given instance, it would be 3 ** 2 = 9.
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