I have written program below without using the __init__
purposely.
class testing:
skills=[]
def addSkill(self,skill):
self.skills.append(skill)
john=testing()
betty=testing()
john.addSkill("FOOTBALL")
betty.addSkill("TENNIS")
print john.skills
Above code gives the output as ['FOOTBALL', 'TENNIS']
.
Now I am not able to understand as why python is appending to the same variable skills
even when I have created two different instances and used self
(self.skills.append(skill)
) to append to particular instance only.
Although if I use __init__
and then declare the skills
set inside it, then my code is working fine.