I was debugging some python code and I came across a bunch of instance methods declared without self. I was curious as to what happens here. Does self get assigned to the first variable declared here?
The code is something like shown below.
class myClass:
 def myFunc (var1, var2):
 return var2
Here is self assigned to var1 ?
 asked Aug 7, 2014 at 18:59
 
 
 
 Devil 
 
 9692 gold badges14 silver badges24 bronze badges
 
 2 Answers 2
Yes, self (that is, the instance) will be assigned to the first variable (assuming there is no decorator like classmethod or staticmethod).
 answered Aug 7, 2014 at 19:00
 
 
 
 BrenBarn 
 
 253k39 gold badges421 silver badges392 bronze badges
 
 
 Sign up to request clarification or add additional context in comments.
 
 
 
 Comments
Your code snippet is equivalent to
class myClass:
 def myFunc(self, var2):
 return var2
The first parameter is passed the instance; name is irrelevant.
 answered Aug 7, 2014 at 19:02
 
 
 
 Daenyth 
 
 37.8k15 gold badges92 silver badges129 bronze badges
 
 Comments
lang-py
 
 
 
print var1and find out?