Home > other > How to function in a class variable references
How to function in a class variable references
Time:09-16
The class Testdd () :
Def out (self) : Global md Md=100 Print (" out function ")
Def other (self) : Print (" othoer function ")
Ss=md + 200 Print (ss)
If __name__=="__main__" : T=Testdd () T.o ther ()
Code as above, perform NameError: the name 'md' is not defined I want the result is the final print out 300, The variables in the md is in out function that can be directly used in other functions, is there any way to do it, I checked global said the can, I use the deficiency is not defined, and the way of, thank you
CodePudding user response:
Md=100
Def other (self) : Print (" othoer function ") Ss=self. Md + 200 Print (ss)