def createCounter():
def counter():
i = [0]
def h():
i = i + 1
return i
return h
return counter
这个为什么不行呢
你的i是list
这里:
你想做的是list里唯一的元素加一,应该改为i[0] + 1
而且,每一次执行函数,你的i都有被重新赋值 i = [0],这个,应该不是你想看到的
Sign in to make a reply
蘭__吾凡
def createCounter():
def counter():
i = [0]
def h():
i = i + 1
return i
return h
return counter
这个为什么不行呢