def createCounter():
x = 0
def counter():
nonlocal x # 声明x不是本层函数的变量
x = x + 1
return x
return counter
counterA = createCounter()
Sign in to make a reply
Young·飘走的船
def createCounter():
x = 0
def counter():
nonlocal x # 声明x不是本层函数的变量
x = x + 1
return x
return counter
counterA = createCounter()