Discuss / Python / 练习

练习

Topic source

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

# 利用闭包返回一个计数器函数,每次调用它返回递增整数:

def createCounter():

    x=0

    def counter():

        nonlocal x

        x=x+1

        return x

    return counter


  • 1

Reply