Hello Friend,
Look at the code below:
class Robot:
def __init__(self,Num):
self.Num = Num
def func(self):
return self.Num
I have defined a class and a constructor. Here 'self' means a pointer to that class itself. So i a assigned the value which i wanted to manipulate.
Please note : Here Num is not a class variable it is an instance variable, so the way you want cant happen.
However using 'self' i can access the variable in the function.
I agree to both the above gentlemen, they are absolutely correct.
after doing the above things, type:
r = Robot(20)
Now:
r.func()
So you will get the output :
20
What you need to learn from this is: the difference between a class variable and an instance variable. I hope it is clear to you from our discussion.
Thanks