import numpy as np
class Y:
def __init__(self):
return None
def f(self,x):
return x
def g(self,x):
return f(x)**2
y=Y()
print y.g(3)
I know the above code will give error, but somehow I want to do the following, is there a modification to do?
__init__shouldn't return anything. If you want it to do nothing, usepass.returnor simply ends with noreturnstatement at all, it returnsNoneby default. Adding areturn Noneto the end of a method that traditionally has noreturnstatement doesn't bother it.__init__()doesn't do anything, just leave it out.g()should bereturn self.f(x)**2.