Discuss / Python / answer

answer

Topic source

viper1090

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

思路: 利用生成器,每次调用时,执行生成器的next方法:

    def tempCount():
        n = 1
        while(True):
            yield n
            n = n + 1
    temp = tempCount()
    def counter():
        return next(temp)
    return counter

-TRQ-

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

不懂为什么不把 tempCount() 赋值给 temp 直接return next(tempCount())会出错


  • 1

Reply