def function_outside():
return "outside"
class Function:
f_o = function_outside()
def function_inside():
return "inside"
print (Function.f_o)
print (Function.function_inside())
If we observe the aforementioned code, why is it a necessity to store the outside-class-function inside an instance variable? Can't we use the global keyword to make the outside-class-function accessible from inside the class? And if we do that, then our first few lines of the code would look like:
def function_outside():
return "outside"
class Function:
global function_outside()
But the code gives a syntax error. I need help :(
Aucun commentaire:
Enregistrer un commentaire