INTRODUCTION TO CLASSES Methods with Arguments

Hi, I am wondering why is there a need to include Circle when writing to return the method as shown here:
class Circle:
pi = 3.14
def area(self, radius):
return Circle.pi * radius ** 2
circle = Circle()
pizza_area = circle.area(6)
teaching_table_area= circle.area(18)
round_room_area= circle.area(5730)
here are the link to the question:
many thanks

pi is a property of the Circle class. So, in order to use that property you also need to reference the class, or instance of that class, that it’s in.
Inside the class it’s usually better and less confusing to use ‘self’ to refer to the class.
So, your return statement could also be written as;

return self.pi * radius ** 2

Hope that helps


It is so clear now! Thank you so much !

1 Like