3 回答

白板的微信
TA貢獻1883條經驗 獲得超3個贊
我認為您對全局變量、返回語句和函數感到困惑。嘗試一下并閱讀我的內聯評論:
x=3
def calculateOO(y):
global x
x=3*y
def calculateXX(z):
y=3*z
return y
print(calculateOO(2))
#prints None, as the function has no return statement
print(x)
#prints 6, as we set x to be global in the calculateOO() function above
print(calculateXX(2))
#prints 6, as we return the value inside the function
print(y)
#causes an error, as we did not set a global y

守著星空守著你
TA貢獻1799條經驗 獲得超8個贊
您還可以執行以下操作:
x=3
def calculateOO(y):
global x
x=3*y
return print((3*y),x)
calculateOO(2)
希望這個解決方案對您有所幫助
添加回答
舉報
0/150
提交
取消