I want to use the variables i have declared inside a function in one class, in another class.
For example i want to use the variable “j” in another class. Is it possible? (I read somewhere that it might have something to do with instance variables but fully couldn’t understand the concept).
class check1:
def helloworld(self):
j = 5
but you don’t need a method to assign a new attribute to a class instance…
Now you can use
check_instance.j(orcheck_instance.k) just like you would use any other variable.This may seems a little bit like magic until you learn that:
is completely equivalent to:
(If you think about it a little bit, that explains what the
selfparameter is).I’m not completely sure what you’re trying to achieve here — There are also class variables which are shared by all instances of the class…