Discuss / Python / 交作业

交作业

Topic source
# -*-coding:utf-8-*-
def count():
    num = 0

    def add():
        nonlocal num
        num += 1
        return num
    return add


x = count()
print(x(), x(), x(), x(), x(), x(), x(), x(), x())

#========================================================
PS F:\pydemo> & C:/Users/Administrator/AppData/Local/Programs/Python/Python37/python.exe f:/pydemo/test.py
1 2 3 4 5 6 7 8 9

  • 1

Reply