Discuss / Python / 参考答案

参考答案

Topic source

lldhsds

#1 Created at ... [Delete] [Delete and Lock User]

参考答案:

def createCounter():    x = 0    def counter():        nonlocal x        x = x + 1        return x    return counter# 测试:counterA = createCounter()print(counterA(), counterA(), counterA(), counterA(), counterA()) # 1 2 3 4 5counterB = createCounter()if [counterB(), counterB(), counterB(), counterB()] == [1, 2, 3, 4]:    print('测试通过!')else:    print('测试失败!')

  • 1

Reply