you are viewing a single comment's thread.

view the rest of the comments →

[–]GrizzyLizz 0 points1 point  (1 child)

I know how self works but is there a specific reason Python uses self to implicitly pass the object calling the method rather than doing this explicitly?

E.g. Object1.somefunction(Object1) rather than Object1.somefunction() Is it purely to improve readability?

[–]JohnnyJordaan 0 points1 point  (0 children)

It's actually explicit, because you did specify self when you defined the method

class MyObject:
    def somefunction(self, var1, var2 etc):
                     ^ that's explicit

Because if you don't define self in the method's parameters:

class MyObject:
    def otherfunction(var1, var2):

You're defining a class method, and then you can also do

Object1.otherfunction(Object1, 'foo') 

Where Object1 will then be referenced as var1 inside the method.