Discuss / Python / My answer

My answer

Topic source

winner丶John

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

def createCounter():

    i = 0

    def counter():

        nonlocal i

        i += 1

        return i

    return counter

winner丶John

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

还有一种采用list的方法

def createCounter():

    L = [0]

    def counter():

        L[0] += 1

        return L[0]

    return counter


  • 1

Reply