+ 1
Is there any way to get value of the variable from the f() method in this class?
class MyClass: n=0 def f(s,v): n=v object=MyClass() object.v=1 print(object.n)
1 Answer
+ 1
I believe, it should be something like this:
class MyClass:
n=0
def f(self,v):
self.n = v
return self.n
MyInstance=MyClass()
print(MyInstance.f(1))