这里为什么必须返回L[0]才行,或者能不能改一下
def createCounter():
L = [0]
def counterA():
L[0]+=1
return L[0]
return counterA
# 测试:
counterA = createCounter()
print(counterA(), counterA(), counterA(), counterA(), counterA()) # 1 2 3 4 5
counterB = createCounter()
if [counterB(), counterB(), counterB(), counterB()] == [1, 2, 3, 4]:
print('测试通过!')
else:
print('测试失败!')
返回 1,2,3,4,5