I don't understand the self parameter?

Why am I adding in self parameters into my functions in classes?

1 Like

self is an obligatory parameter in all of your Python functions. It references the object being called, and I’ve seen this example which I really like:

class Example:
    def some_method(self):
        print('hello world');

example = Example()
example.some_method()
Example.some_method(example)

In the first time the method is called, Python automatically passes the example object as the self parameter. The second time I call it, I’m calling it on the class and passing the example object as the self parameter.

Hope this helps!

3 Likes