2024-06-28 18:49:14 发布
网友
我有以下代码:
def test(): def printA(): def somethingElse(): pass print(a) aHA = a[2] a = [1, 2, 3] while True: printA() test()
我注意到这段代码可以很好地工作,但是如果我将aHA更改为a,它会说a没有定义。你知道吗
aHA
a
有没有办法将a设置为printA中的另一个值?你知道吗
在Python3中,可以将变量设置为非局部变量
def test(): a = [1, 2, 3] def printA(): nonlocal a def somethingElse(): pass print(a) a = a[2] while True: printA() test()
在Python3中,可以将变量设置为非局部变量
相关问题 更多 >
编程相关推荐