Https://www.codecademy.com/courses/learn-python-3/lessons/data-types/exercises/methods-with-arguments

Hi there,

In the ‘Methods with Arguments’-lesson, the method area has the object ‘self’. But what input does that object actually listen to? In the process of calculating the area of the circles, it seems obsolete. Obviously it isn’t, but I don’t understand why it needs to be there, as the obly object that is used is the radius, right?

Thanks!

no link to the lesson?

An example:

class Circle:
   def radius(self):
      # body of the method

circle_one = Circle()
circle_one.radius()

so we have an instance/object (circle_one), and when we call radius method, python takes cares of binding self.

self is the current instance/object, given we can have multiple instances/objects. But when calling a method on an instance/object, python will bind/provide the argument for self parameter for us

When we would call the method on the class, we need to provide the argument for self:

Circle.radius(circle_one)
3 Likes

https://www.codecademy.com/courses/learn-python-3/lessons/data-types/exercises/methods

This is the link, sorry. And thanks for your reply.

I think I just get stuck trying to understand the working and the actual use of classes, instances and methods. As this lesson just started, for me it seems a bit like creating a lot of variables of which the use does not become clear. I don’t yet understand the differences between classes, instances, objects etc.

1 Like

Sorry this is the proper link:

https://www.codecademy.com/courses/learn-python-3/lessons/data-types/exercises/methods-with-arguments

1 Like

This will always be a problem when first learning classes. The abstraction classes introduce do not pay off until you have a larger code base. Then classes help to structure and organize your code

in my example, Circle is the class. Which is like a blue-print. then circle_one is the instance/object. Which is the actual object build from the blue-print

3 Likes

Thanks! It will probably become clearer in the near future. I’ve made it this ‘far’, so I guess I’ll just carry on.

2 Likes