class Testdd():
def out(self):
global md
md =100
print("out函式")
def other(self):
print("othoer函式")
ss = md+ 200
print(ss)
if __name__ =="__main__":
t = Testdd()
t.other()
代碼如上,執行報NameError: name 'md' is not defined
我想要的結果是最后列印出300,
就是在out函式中的變數md,可以直接在other函式中使用,有什么辦法可以做到嗎,
我查了global說的可以,我使用缺報沒有定義,求大佬的辦法,謝謝了
uj5u.com熱心網友回復:
md = 100
def other(self):
print("othoer函式")
ss = self.md + 200
print(ss)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/7044.html
