我只是创建了函数 (Python) 并想使用在函数外部定义的变量并且发生了错误
def outside_variable_show(status):
if status == 1:
crrnt_nmbr = crrnt_nmbr + 1
print (crrnt_nmbr)
status = 1
crrnt_nmbr = 0
print (crrnt_nmbr)
outside_variable_show(1)
注意:“crrnt_nmbr”必须在函数内外使用。
请告诉我实现它的方法。太感谢了。
试试这个:
def outside_variable_show(status):
global crrnt_nmbr
if status == 1:
crrnt_nmbr = crrnt_nmbr + 1
print (crrnt_nmbr)
status = 1
crrnt_nmbr = 0
print (crrnt_nmbr)
outside_variable_show(1)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句