Discuss / Python / 我想得比较简单

我想得比较简单

Topic source

永远短毛

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

def createCounter(): i=0 def counter(): nonlocal i i+=1 return i return counter f=createCounter() print(f(),f(),f()) l=createCounter() L=[l(),l(),l()] print(L) for n in L: print(n)

运行结果 1 2 3 [1, 2, 3] 1 2 3


  • 1

Reply