看了各位大佬的答案,不知道有nonlocal这玩意。。于是想起了之前学的生成器,有点绕也算是可以吧
def createCounter(): def counter(): x = 1 while True: yield x x += 1 def func(): return next(c) c = counter() return func
Sign in to make a reply
纸丶两面白
看了各位大佬的答案,不知道有nonlocal这玩意。。于是想起了之前学的生成器,有点绕也算是可以吧
def createCounter(): def counter(): x = 1 while True: yield x x += 1 def func(): return next(c) c = counter() return func