python迭代器和生成器
iter()用于创建迭代器,next()用于输出迭代器的下一个元素:
names = ["微湘菜", "小湘菜", "大湘菜", "巨湘菜"] iterName = iter(names) for i in range(4): print(next(iterName))
iter()用于创建迭代器,next()用于输出迭代器的下一个元素:
names = ["微湘菜", "小湘菜", "大湘菜", "巨湘菜"] iterName = iter(names) for i in range(4): print(next(iterName))