思路: 利用生成器,每次调用时,执行生成器的next方法:
def tempCount(): n = 1 while(True): yield n n = n + 1 temp = tempCount() def counter(): return next(temp) return counter
不懂为什么不把 tempCount() 赋值给 temp 直接return next(tempCount())会出错
Sign in to make a reply
viper1090
思路: 利用生成器,每次调用时,执行生成器的next方法: