+ 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)

24th Mar 2018, 9:41 AM
Alex K
Alex K - avatar
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))
24th Mar 2018, 10:59 AM
strawdog
strawdog - avatar