Discuss / Python / 交作业

交作业

Topic source

看了各位大佬的答案,不知道有nonlocal这玩意。。于是想起了之前学的生成器,有点绕也算是可以吧

def createCounter(): def counter(): x = 1 while True: yield x x += 1 def func(): return next(c) c = counter() return func


  • 1

Reply