Discuss / Python / 做习题打卡

做习题打卡

Topic source

蜜蜂-Leo

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

又是抄来的……

def createCounter():
    i=0
    def f():
        nonlocal i
        i += 1
        return i
    return f

哈哈哈

nonlocal i

目的就是表明将 f()的i 变量和外部的i为同一变量,

参考这篇文章学习一下:https://blog.csdn.net/xcyansun/article/details/79672634

蜜蜂-Leo

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

多谢!我偶尔学一下,计划囫囵吞枣般过一遍,然后再重头看吧。不然完全和看天书一样


  • 1

Reply